Have seen how to pull code out of the code-behind and into ViewModel, and then out of the ViewModel into Services.
- less brittle
Ways for XAML elements to invoke methods in the ViewModel:
- ICommand – traditional and supported in most MVVM toolkits
- CallMethodAction – introduced in Expression Blend 4
Commands and CallMethodAction are a great way to separate the View from ViewModel, keeping the contract at just a binding statement or name of a method.
More Vacation button disabled by default
AddVacationBonusCommand is a property on EmployeeListViewModel
Introduced with Expression Blend4 – an easy and designer friendly way to wire any event from any control to a method.
Installed Expression Blend Preview for Silverlight 5.
reference Microsoft.Expression.Interactions, System.Windows.Interactivity
Easy way to wire up a button click whilst not being tightly coupled.
View Specific Entities
eg not using Employee object all the way to the UI. If employee changes in the db, then have to change the UI.
So update all client side places that once used Employee to use EmployeeViewModel.
Just surfacing the required data to the UI using EmployeeViewModel class which the EmployeeListViewModel uses
Interfaces, IoC and ViewModel Locators
EmployeeList View is tightly coupled to EmployeeListViewModel
Similarly the EmployeeListViewModel is tightly coupled to the EmployeeDataService and EmployeeVacationBonusService.
- can be useful to not have this if want to swap out datastore
Leave for now and see what can do with testing without this..
Need to set the correct aspx as start page otherwise it will try to run the test project.
http://silverlight.codeplex.com/releases/view/78435 – Silverlight 5 Toolkit
Silverlight Unit Testing Framework..didn’t install the templates into VS2012
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Testing - DLLs are here
Got this working on already existing templates
Testing the EmployeeListViewModel
Test 'MvvmApplication.NUnitTests.EmployeeListViewModelTests.SelectedEmployeeCanBeSetAndRetrieved' failed: System.IO.FileNotFoundException : Could not load file or assembly 'System.Windows, Version=188.8.131.52, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
Class1.cs(20,0): at MvvmApplication.NUnitTests.EmployeeListViewModelTests.SelectedEmployeeCanBeSetAndRetrieved()
Could use SilverUnit which doesn’t have these issues.
http://stackoverflow.com/questions/10891403/silverlight-5-and-nunit – had to add in System.Windows into the Unit Testing project from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0
I added in a normal project reference for MvvmApplication.Core as got version conflicts when just adding the dll from debug (however I get a warning doing it this way)
Added in System.ServiceModel into the Nunit project.
The SilverlightTest base class supplies the critical EnqueueTestComple method, that tells the test framework that the method is complete and can release it from its holding pattern created by the async attribute.
**can’t easily create a new unit test project.
Copied old test project across, then wired up the .Web project to include the newly copied project.
So can now do tests with TestDriven.NET on the ViewModels, and the SL Test Runner on Async.
http://code.google.com/p/nunit-silverlight/ – unofficial port of unit for SL …Nov 2010. SL4
http://agunit.codeplex.com/ – R# plugin to allow unit test to run… supports: MS Test Framework for SL Toolkit, NUnit-Silverlight, xUnitContrib-Silverlight… quite up to date 2012.
http://blogs.msdn.com/b/bharry/archive/2012/07/09/coded-ui-testing-support-for-silverlight.aspx – coded UI support for SL 5.