Download - Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP
![Page 1: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/1.jpg)
Unit testing MVVM in Silverlight
Timmy Kokke
Silverlight / ASP.Net DeveloperUNIT4 Internet SolutionsExpression Blend MVP
![Page 2: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/2.jpg)
Agenda
Basics of MVVMUnit TestingSilverlight Unit Testing frameworkStatLight
![Page 3: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/3.jpg)
Basic MVVM
Model
View
ViewModel
![Page 4: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/4.jpg)
Basic MVVM
Model
View
ViewModel
![Page 5: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/5.jpg)
Basic MVVM
Model
View
ViewModel
![Page 6: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/6.jpg)
Basic MVVM
Model
View
ViewModel
![Page 7: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/7.jpg)
Basic MVVM
Model
View
ViewModel
DatabindingCommands
MethodsEvents
![Page 8: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/8.jpg)
Unit Testing
Unit tests are
consistent, isolated, fast and repeatable
![Page 9: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/9.jpg)
Unit Testing
Test only small units of workTestName = Requirement1 Assert per testSelf explanatoryReadability over Maintainability
![Page 10: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/10.jpg)
Silverlight Unit Test Framework
Silverlight Toolkit http://silverlight.codeplex.com
Runs in browser, no support for MsTest
![Page 11: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/11.jpg)
Writing Tests
Demo
![Page 12: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/12.jpg)
Writing Tests
[TestClass]public class ExampleTests{
[TestMethod] public class Adding_1_And_1_Should_Be_2(){ int result = 1 + 1; Assert.AreEqual(2, result); }}
![Page 13: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/13.jpg)
Serv
er
Silv
erlig
ht C
lien
t
Demo Project
GamesViewModel
GamesView
GamesDataService
WCF Ria Service
Database
![Page 14: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/14.jpg)
Mvvm Demo Project
Demo
![Page 15: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/15.jpg)
Un
it Test
Serv
er
Silv
erl
igh
t C
lien
tDemo Project
GamesViewModel
GamesView
GamesDataService
WCF Ria Service
Database
TestGamesDataService
IGamesDataService
GamesViewModelTests
![Page 16: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/16.jpg)
Silverlight Unit testing
Demo
![Page 17: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/17.jpg)
[Tag(“anything”)]
[TestMethod][Tag("Rating")]public void Setting_Ratings_Should_Set_AverageRating(){ Rating rating = new Rating();
rating.GameplayRating = 4; rating.GraphicsRating = 2;
Assert.AreEqual(3, rating.AverageRating);}
![Page 18: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/18.jpg)
[Description(“what’s goin’ on”)]
[TestMethod][Description("Testing implementation of IDataErrorInfo."+ "Empty String Name should return Error.")]public void Getting_ErrorInfo_For_Empty_Name_Should_Return_Error(){ Rating errorInfo = new Rating {Name = string.Empty}; string result = errorInfo["Name"]; Assert.IsFalse(string.IsNullOrWhiteSpace(result));}
![Page 19: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/19.jpg)
[Asynchonous]
[TestMethod][Asynchronous]public void Executing_InitializeCommand_Should_Get_Publishers(){ PublishersViewModel viewModel = new PublishersViewModel( new TestPublishersDataService()); viewModel.PropertyChanged += (s, a) =>
{ Assert.IsTrue(viewModel.Publishers != null); EnqueueTestComplete(); }; viewModel.InitializeCommand.Execute(null);}
![Page 20: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/20.jpg)
[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 = new RatingViewModel(new TestGamesDataService());
viewModel.SubmitCommand.Execute(null);}
![Page 21: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/21.jpg)
[TimeOut(250)]
[TestMethod] [Asynchronous][Timeout(250)]public void Executing_GetMoreCommand_Should_Respond_In_250ms(){ PublishersViewModel viewModel = new PublishersViewModel(new TestPublishersDataService());
viewModel.PropertyChanged += (s, a) => { Assert.IsTrue(true); EnqueueTestComplete(); }; viewModel.GetMoreCommand.Execute(null);}
![Page 22: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/22.jpg)
[ExpectedException(typeof(Exception))]
[TestMethod][ExpectedException(typeof(ArgumentNullException))]public void Executing_SubmitCommand_With_Null_Should_Throw_Exception(){ RatingViewModel viewModel = new RatingViewModel(new TestGamesDataService());
viewModel.SubmitCommand.Execute(null);}
![Page 23: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/23.jpg)
StatLight
Command line toolhttp://statlight.codeplex.comPossible to integrate in TFS buildContinuous mode
![Page 24: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/24.jpg)
StatLight
Demo
![Page 25: Timmy Kokke Silverlight / ASP.Net Developer UNIT4 Internet Solutions Expression Blend MVP](https://reader036.vdocument.in/reader036/viewer/2022070306/5518c433550346b31f8b56ea/html5/thumbnails/25.jpg)
Unit testing MVVM in Silverlighthttp://silverlight.codeplex.comhttp://statlight.codeplex.com
Timmy Kokke [email protected] http://twitter.com/sorskoot http://www.timmykokke.com
Silverlight and Expression Usergroup http://www.sixin.nl 9 November next meeting !