public void Register_Should_Return_Error_If_Username_Is_Missing()
 {
     var model = new RegisterModel
     {
         Username = string.Empty,
         Email = email,
         Question = question,
         Answer = answer,
         Password = password
     };
     var result = controller.Register(model);
     AssertRegisterViewResultOnError(controller, result, "username",
                                     "Username is required",
                                     string.Empty, email,
                                     question, answer, password);
 }
 public void Register_Should_Return_Error_If_Username_Is_Invalid()
 {
     var invalidUsername = "******";
     var model = new RegisterModel
     {
         Username = invalidUsername,
         Email = email,
         Question = question,
         Answer = answer,
         Password = password
     };
     var result = controller.Register(model);
     AssertRegisterViewResultOnError(controller, result, "username",
                                     "Username is invalid",
                                     invalidUsername, email, question,
                                     answer, password);
 }
 public void Register_Should_Return_Error_If_Email_Is_Invalid()
 {
     var invalidEmail = "bad @ email .#.com";
     var model = new RegisterModel
     {
         Username = username,
         Email = invalidEmail,
         Question = question,
         Answer = answer,
         Password = password
     };
     var result = controller.Register(model);
     AssertRegisterViewResultOnError(controller, result, "email",
                                     "Email is invalid",
                                     username, invalidEmail, 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);
 }
        public void Register_Should_Call_SetAuthCookie_On_Success()
        {
            var model = new RegisterModel
            {
                Username = username,
                Email = email,
                Question = question,
                Answer = answer,
                Password = password
            };
            //create mocks and set expectations
            mocks.MembershipProvider
                .Expect(p => p.CreateUser(username, password,
                                          email, question, answer, true,
                                          null, out createstatus))
                .Returns(new Mock<MembershipUser>().Object);
            mocks.FormsAuthentication
                .Expect(a => a.SetAuthCookie(username, false));

            //run tests
            var result = controller.Register(model);
            //assert result
            Assert.IsNotNull(result);
            result.AssertRedirectToRouteResult("Index", "home");
            //verify mocks expectations have been met
            mocks.MembershipProvider.VerifyAll();
            mocks.FormsAuthentication.VerifyAll();
        }
 public void Register_Redirects_To_Home_Index_On_Success()
 {
     //set expectations
     mocks.MembershipProvider
         .Expect(p => p.CreateUser(username, password,
                                   email, question, answer, true,
                                   null, out createstatus))
         .Returns(new Mock<MembershipUser>().Object);
     //run tests
     var model = new RegisterModel
                     {
                         Username = username,
                         Email = email,
                         Question = question,
                         Answer = answer,
                         Password = password
                     };
     var result = controller.Register(model);
     //assert result
     result.AssertRedirectToRouteResult("Index", "home");
 }