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));
        }
        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_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);
        }