public void SetUp()
 {
     mocks = new Mocks();
     controller = new AccountController(mocks.FormsAuthentication.Object,
                                mocks.MembershipProvider.Object);
 }
 private static void AssertRegisterViewResultOnError(AccountController ac,
                                                     ActionResult result,
                                                     string errorKey,
                                                     string errorMessage,
                                                     string username,
                                                     string email,
                                                     string question,
                                                     string answer,
                                                     string password)
 {
     //todo refactor register method to take in the registermodel
     Assert.IsNotNull(result);
     Assert.IsInstanceOfType(typeof (ViewResult), result);
     ac.ViewData.ModelState.AssertErrorMessage(errorKey, errorMessage);
     Assert.IsInstanceOfType(typeof (RegisterModel),
                             ((ViewResult) result).ViewData.Model);
     var model = (((ViewResult) result).ViewData.Model as RegisterModel);
     model.AssertModel(username, email, question, answer, password);
 }
 public void Register_Should_Fail_If_CreateUser_Fails(MembershipCreateStatus status, string errorMessage)
 {
     var model = new RegisterModel
     {
         Username = username,
         Email = email,
         Question = question,
         Answer = answer,
         Password = password
     };
     //create fake membership provider & mocks
     var fakeProvider = new FakeMembershipProvider();
     //tell the fake provider what status to return when CreateUser is called
     fakeProvider.SetFakeStatus(status);
     //run tests
     controller = new AccountController(mocks.FormsAuthentication.Object, fakeProvider);
     var result = controller.Register(model);
     AssertRegisterViewResultOnError(controller, result, "provider",
                                     errorMessage,
                                     username, email, question,
                                     answer, password);
 }