
Note that Action is ignored when matching parameters - it's difficult to match Action and Func and usually not worth it. This way you verify that command calls business layer as expected. Var testedViewModel = new LoginViewModel(userServiceFake) Example with FakeItEasy: var userServiceFake = A.Fake() How do one goes with such test? By using mock. Now, one might ask, what is the purpose of testing command when you already have test for underlying business logic? The purpose is to verify that business logic is called and with correct parameters. Given that it's private, it should be tested it via LoginCommand.
#Passwordbox service code
Your view model has one relevant piece of code worth testing, which is Login method. Now my test is not on the ViewModel itself but directly to the Business layer.Īm I on the right path, or is there a fundamental flaw in my pattern implementation? UserService.Login("nonexistingusername", passwordBox.SecurePassword, b => Assert.AreEqual(b, false)) PasswordBox passwordBox = new PasswordBox IUserService userService = new DesignUserService() Public void IncorrectUsernameCorrectPassword() UserData is a static class which makes calls to the database (Entity Framework). String rawPassword = Security.ComputeHashString(password, user.Salt) Var user = _users.FirstOrDefault(u => u.UserName.ToLower() = userName.ToLower()) Public void Login(String userName, SecureString password, Action callback)

Business mockup class for design and test time: public class DesignUserService : IUserService MessageBox.Show("Wrong username or password") īinding and commands work fine so there is no questions. _userService.Login(UserName, passwordBox.SecurePassword, result => Throw new Exception("PasswordBox is null") PasswordBox passwordBox = passwordBoxObject as PasswordBox Private void Login(Object passwordBoxObject)

Public LoginViewModel(IUserService userService)

/ Initializes a new instance of the LoginViewModel class. Private readonly IUserService _userService Login ViewModel: public class LoginViewModel : ViewModelBase ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default) Now after some toying I created a standard template from MVVM Light and did this: What I used to do ("normal" WPF), was creating my Views with a Business layer and perhaps a datalayer (which usually contains my entities created by a service or the Entity Framework). I am not a regular with the MVVM pattern and this is basically my first time playing with it.
