Unit testing mvvm in silverlight
Download
1 / 25

Unit testing MVVM in Silverlight - PowerPoint PPT Presentation


  • 73 Views
  • Uploaded on

Unit testing MVVM in Silverlight. Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP. Agenda. Basics of MVVM Unit Testing Silverlight Unit Testing framework StatLight. Basic MVVM. View. ViewModel. Model. Basic MVVM. View. ViewModel. Model.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Unit testing MVVM in Silverlight' - hinda


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Unit testing mvvm in silverlight

Unit testing MVVM in Silverlight

Timmy Kokke

Silverlight / ASP.Net Developer

UNIT4 Internet Solutions

Expression Blend MVP


Agenda
Agenda

  • Basics of MVVM

  • Unit Testing

  • Silverlight Unit Testing framework

  • StatLight


Basic mvvm
Basic MVVM

View

ViewModel

Model


Basic mvvm1
Basic MVVM

View

ViewModel

Model


Basic mvvm2
Basic MVVM

View

ViewModel

Model


Basic mvvm3
Basic MVVM

View

ViewModel

Model


Basic mvvm4
Basic MVVM

View

Databinding

Commands

ViewModel

Methods

Events

Model


Unit testing
Unit Testing

Unit tests are

consistent,isolated, fastand repeatable


Unit testing1
Unit Testing

  • Test only small units of work

  • TestName = Requirement

  • 1 Assert per test

  • Self explanatory

  • Readability over Maintainability


Silverlight unit test framework
Silverlight Unit Test Framework

  • Silverlight Toolkit http://silverlight.codeplex.com

  • Runs in browser, no support for MsTest



Writing tests1
Writing Tests

  • [TestClass]

  • public class ExampleTests{

  • [TestMethod]

  • public class Adding_1_And_1_Should_Be_2(){

  • int result = 1 + 1;

  • Assert.AreEqual(2, result);

  • }

  • }


Demo project
Demo Project

Silverlight Client

GamesView

GamesViewModel

GamesDataService

Server

WCF Ria Service

Database


Mvvm demo project

Mvvm Demo Project

Demo


Demo project1
Demo Project

Silverlight Client

Unit Test

GamesView

GamesViewModelTests

GamesViewModel

IGamesDataService

GamesDataService

TestGamesDataService

Server

WCF Ria Service

Database



Tag anything
[Tag(“anything”)]

  • [TestMethod][Tag("Rating")]public voidSetting_Ratings_Should_Set_AverageRating(){Rating rating = newRating();rating.GameplayRating = 4;rating.GraphicsRating = 2;Assert.AreEqual(3, rating.AverageRating);}


Description what s goin on
[Description(“what’s goin’ on”)]

  • [TestMethod][Description("Testing implementation of IDataErrorInfo."+             "Empty String Name should return Error.")]publicvoidGetting_ErrorInfo_For_Empty_Name_Should_Return_Error(){Rating errorInfo = new Rating {Name = string.Empty};string result = errorInfo["Name"];Assert.IsFalse(string.IsNullOrWhiteSpace(result));}


Asynchonous
[Asynchonous]

  • [TestMethod][Asynchronous]publicvoid Executing_InitializeCommand_Should_Get_Publishers(){PublishersViewModel viewModel = newPublishersViewModel(

  • newTestPublishersDataService());viewModel.PropertyChanged += (s, a) => {Assert.IsTrue(viewModel.Publishers != null);          EnqueueTestComplete();};viewModel.InitializeCommand.Execute(null);}


Bug known failure workitem 1234
[Bug(“Known failure”)][WorkItem(1234)]

  • [TestMethod][Bug("Submitting is not implemented at this moment.")][WorkItem(1543)]        [Asynchronous]public void Executing_SubmitCommand_Should_Navigate_To_GamesList(){DecoupledEventAggregator.GetInstance()

  • .GetEvent<NavigateToEvent>().Subscribe((a) =>{

  • Assert.IsTrue(true);                   EnqueueTestComplete();});RatingViewModel viewModel = 

  • newRatingViewModel(newTestGamesDataService()); viewModel.SubmitCommand.Execute(null);}


Timeout 250
[TimeOut(250)]

  • [TestMethod]        [Asynchronous][Timeout(250)]public void Executing_GetMoreCommand_Should_Respond_In_250ms(){PublishersViewModel viewModel = 

  • new PublishersViewModel(newTestPublishersDataService());viewModel.PropertyChanged += (s, a) =>        {Assert.IsTrue(true);            EnqueueTestComplete();};viewModel.GetMoreCommand.Execute(null);}


Expectedexception typeof exception
[ExpectedException(typeof(Exception))]

  • [TestMethod][ExpectedException(typeof(ArgumentNullException))]public void Executing_SubmitCommand_With_Null_Should_Throw_Exception(){RatingViewModel viewModel = newRatingViewModel(newTestGamesDataService());viewModel.SubmitCommand.Execute(null);}


Statlight
StatLight

  • Command line tool

  • http://statlight.codeplex.com

  • Possible to integrate in TFS build

  • Continuous mode


Statlight1

StatLight

Demo


Unit testing mvvm in silverlight1
Unit testing MVVM in Silverlight

  • http://silverlight.codeplex.com

  • http://statlight.codeplex.com

  • Timmy Kokke [email protected]://twitter.com/sorskoothttp://www.timmykokke.com

  • Silverlight and Expression Usergroup http://www.sixin.nl 9 November next meeting !


ad