public void ResendConfirmation_POST_Should_SendEmail_And_Show_SignupComplete_View_And_Set_TempData()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;
            SiteSettings siteSettings = _settingsService.GetSiteSettings();

            string email = "*****@*****.**";

            _userService.AddUser(email, "test", "password", false, true);
            UserViewModel model = new UserViewModel(_userService.GetUser("*****@*****.**", false));

            SignupEmailStub signupEmail    = new SignupEmailStub(_applicationSettings, _repository, _emailClientMock);
            UserController  userController = new UserController(_applicationSettings, _userService, _userContext, _settingsService, signupEmail, null);

            userController.SetFakeControllerContext();

            // Act
            ActionResult result = userController.ResendConfirmation(email);

            // Assert
            ViewResult viewResult = result.AssertResultIs <ViewResult>();

            Assert.That(viewResult.ViewName, Is.EqualTo("SignupComplete"));
            Assert.That(viewResult.TempData["resend"], Is.EqualTo(true));
            Assert.That(signupEmail.IsSent, Is.EqualTo(true));
        }
        public void Signup_POST_Should_Not_Send_Email_With_Invalid_ModelState()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;

            SiteSettings siteSettings = _settingsService.GetSiteSettings();

            siteSettings.AllowUserSignup = true;

            SignupEmailStub signupEmail    = new SignupEmailStub(_applicationSettings, _repository, _emailClientMock);
            UserController  userController = new UserController(_applicationSettings, _userService, _userContext, _settingsService, signupEmail, null);

            userController.SetFakeControllerContext();
            userController.ModelState.AddModelError("key", "this is used to force ModelState.IsValid to false");

            UserViewModel model = new UserViewModel();

            // Act
            ActionResult result = userController.Signup(model, null);

            // Assert
            ViewResult viewResult = result.AssertResultIs <ViewResult>();

            Assert.That(viewResult.ViewName, Is.Not.EqualTo("Signup"));
            Assert.That(userController.ModelState.Count, Is.EqualTo(1));
            Assert.That(signupEmail.IsSent, Is.False);
        }
        public void Signup_POST_Should_Set_ModelState_Error_From_SecurityException()
        {
            // Arrange
            SiteSettings siteSettings = _settingsService.GetSiteSettings();

            siteSettings.AllowUserSignup = true;

            SignupEmailStub signupEmail    = new SignupEmailStub(_applicationSettings, _repository, _emailClientMock);          // change the signup email
            UserController  userController = new UserController(_applicationSettings, _userService, _userContext, _settingsService, signupEmail, null);

            userController.SetFakeControllerContext();

            _userService.ThrowSecurityExceptionOnSignup = true;

            UserViewModel model = new UserViewModel();

            // Act
            ActionResult result = userController.Signup(model, null);

            // Assert
            ViewResult viewResult = result.AssertResultIs <ViewResult>();

            Assert.That(viewResult.ViewName, Is.Not.EqualTo("Signup"));
            Assert.That(userController.ModelState.Count, Is.EqualTo(1));
            Assert.That(userController.ModelState["General"].Errors[0].ErrorMessage, Is.EqualTo("ThrowSecurityExceptionOnSignup"));
        }
        public void Signup_POST_Should_Send_Email()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;

            SiteSettings siteSettings = _settingsService.GetSiteSettings();

            siteSettings.AllowUserSignup = true;

            SignupEmailStub signupEmail    = new SignupEmailStub(_applicationSettings, _repository, _emailClientMock);
            UserController  userController = new UserController(_applicationSettings, _userService, _userContext, _settingsService, signupEmail, null);

            userController.SetFakeControllerContext();

            UserViewModel model = new UserViewModel();

            model.NewEmail             = "blah@localhost";
            model.Password             = "******";
            model.PasswordConfirmation = "password";

            // Act
            ActionResult result = userController.Signup(model, null);

            // Assert
            ViewResult viewResult = result.AssertResultIs <ViewResult>();

            Assert.That(viewResult.ViewName, Is.EqualTo("SignupComplete"));
            Assert.That(signupEmail.IsSent, Is.True);
            Assert.That(signupEmail.ViewModel, Is.EqualTo(model));
        }