Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public void Step3_Should_Return_ViewResult_With_SettingsViewModel()
        {
            // Arrange
            SettingsViewModel existingModel = new SettingsViewModel();

            existingModel.ConnectionString = "connectionstring";
            existingModel.SiteUrl          = "siteurl";
            existingModel.SiteName         = "sitename";

            // Act
            ActionResult result = _installController.Step3(existingModel);

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

            viewResult.AssertViewRendered();

            SettingsViewModel model = viewResult.ModelFromActionResult <SettingsViewModel>();

            Assert.NotNull(model, "Null model");

            /* The view is responsible for passing these across,
             * but this gives a rough indication that no data is lost between steps */
            Assert.That(model.ConnectionString, Is.EqualTo(existingModel.ConnectionString));
            Assert.That(model.SiteUrl, Is.EqualTo(existingModel.SiteUrl));
            Assert.That(model.SiteName, Is.EqualTo(existingModel.SiteName));
        }
Exemplo n.º 4
0
        public void UnattendedSetup_Should_Add_Admin_User_And_Set_Default_Site_Settings()
        {
            // Arrange
            SettingsViewModel existingModel = new SettingsViewModel();

            SetMockDataStoreType(existingModel);

            // Act
            ActionResult result = _installController.Unattended("mock datastore", "fake connection string");

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.EqualTo("Unattended installation complete"));

            UserViewModel adminUser = _userService.ListAdmins().FirstOrDefault();             // check admin

            Assert.That(adminUser, Is.Not.Null);

            ApplicationSettings appSettings = _configReaderWriter.ApplicationSettings;             // check settings

            Assert.That(appSettings.DataStoreType.Name, Is.EqualTo("mock datastore"));
            Assert.That(appSettings.ConnectionString, Is.EqualTo("fake connection string"));
            Assert.That(appSettings.UseObjectCache, Is.True);
            Assert.That(appSettings.UseBrowserCache, Is.True);

            SiteSettings settings = _settingsService.GetSiteSettings();

            Assert.That(settings.AllowedFileTypes, Is.EqualTo("jpg,png,gif,zip,xml,pdf"));
            Assert.That(settings.Theme, Is.EqualTo("Responsive"));
            Assert.That(settings.SiteName, Is.EqualTo("my site"));
            Assert.That(settings.SiteUrl, Is.EqualTo("http://localhost"));
        }
Exemplo n.º 5
0
        public void unattendedsetup_should_add_admin_user_and_set_default_site_settings()
        {
            // Arrange

            // Act
            ActionResult result = _installController.Unattended("mock datastore", "fake connection string");

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.EqualTo("Unattended installation complete"));

            Assert.That(_installerRepository.AddAdminUserCalled, Is.True);
            Assert.That(_installerRepository.DatabaseName, Is.EqualTo("mock datastore"));
            Assert.That(_installerRepository.ConnectionString, Is.EqualTo("fake connection string"));

            ApplicationSettings appSettings = _configReaderWriter.ApplicationSettings;             // check settings

            Assert.That(appSettings.UseObjectCache, Is.True);
            Assert.That(appSettings.UseBrowserCache, Is.True);

            SiteSettings settings = _installerRepository.SiteSettings;

            Assert.That(settings.AllowedFileTypes, Is.EqualTo("jpg,png,gif,zip,xml,pdf"));
            Assert.That(settings.MarkupType, Is.EqualTo("Creole"));
            Assert.That(settings.Theme, Is.EqualTo("Responsive"));
            Assert.That(settings.SiteName, Is.EqualTo("my site"));
            Assert.That(settings.SiteUrl, Is.EqualTo("http://localhost"));
        }
Exemplo n.º 6
0
        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"));
        }
Exemplo n.º 7
0
        public void ResetPassword_POST_Should_Have_ResetPasswordSent_View_And_Should_Send_ResetPassword_Email()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;
            SiteSettings siteSettings = _settingsService.GetSiteSettings();

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

            _userService.AddUser(email, "test", "test", false, true);
            _userService.Users.First(x => x.Email == email).IsActivated = true;

            ResetPasswordEmailStub resetEmail     = new ResetPasswordEmailStub(_applicationSettings, _repository, _emailClientMock);
            UserController         userController = new UserController(_applicationSettings, _userService, _userContext, _settingsService, null, resetEmail);

            userController.SetFakeControllerContext();

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

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

            Assert.That(viewResult.ViewName, Is.EqualTo("ResetPasswordSent"));
            Assert.That(resetEmail.IsSent, Is.True);
            Assert.That(resetEmail.Model.ExistingEmail, Is.EqualTo(email));
            Assert.That(resetEmail.Model.PasswordResetKey, Is.EqualTo(UserServiceMock.RESETKEY));
        }
Exemplo n.º 8
0
        public void Profile_POST_Should_Update_Password_If_Changed()
        {
            // Arrange
            string email       = "*****@*****.**";
            string newPassword = "******";

            _userService.AddUser(email, "profiletest", "password", false, true);
            User newUser = _userService.Users.First(x => x.Email == email);

            newUser.IsActivated = true;

            string existingHash = newUser.Password;

            Guid userId = newUser.Id;

            _userContext.CurrentUser = userId.ToString();

            UserViewModel model = new UserViewModel(newUser);

            model.Password = newPassword;

            // Act
            ActionResult result = _userController.Profile(model);

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

            viewResult.AssertViewRendered();

            User user = _userService.GetUser(email);

            Assert.That(user.Password, Is.Not.EqualTo(existingHash));
            Assert.That(user.Password, Is.Not.Empty.Or.Null);
            Assert.That(user.Password.Length, Is.GreaterThan(10));
        }
Exemplo n.º 9
0
        public void Profile_POST_Should_Update_Password_If_Changed()
        {
            // Arrange
            string email          = "*****@*****.**";
            string newPassword    = "******";
            string hashedPassword = User.HashPassword(newPassword, "");

            _userService.AddUser(email, "profiletest", "password", false, true);
            _userService.Users.First(x => x.Email == "*****@*****.**").IsActivated = true;
            Guid userId = _userService.GetUser(email).Id;

            _userContext.CurrentUser = userId.ToString();

            UserViewModel model = new UserViewModel(_userService.GetUser(email));             // use the same model, as profile() updates everything.

            model.Password = newPassword;

            // Act
            ActionResult result = _userController.Profile(model);

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

            viewResult.AssertViewRendered();

            User user = _userService.GetUser(email);

            Assert.That(user.Password, Is.EqualTo(hashedPassword));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        public void Activate_Should_Return_View_When_Key_Is_Valid()
        {
            // Arrange

            // Act
            ActionResult result = _userController.Activate(UserServiceMock.ACTIVATIONKEY);

            // Assert
            result.AssertResultIs <ViewResult>();
        }
Exemplo n.º 12
0
        public void activate_should_return_view_when_key_is_valid()
        {
            // Arrange

            // Act
            ActionResult result = _userController.Activate(UserServiceMock.ACTIVATIONKEY);

            // Assert
            result.AssertResultIs <ViewResult>();
        }
Exemplo n.º 13
0
        public void LoggedInAs_Should_Return_PartialView()
        {
            // Arrange + Act
            ActionResult result = _userController.LoggedInAs();

            // Assert
            PartialViewResult partialViewResult = result.AssertResultIs <PartialViewResult>();

            partialViewResult.AssertPartialViewRendered();             // check the view matches the action name
        }
Exemplo n.º 14
0
        public void activate_should_have_model_error_when_key_is_invalid()
        {
            // Arrange

            // Act
            ActionResult result = _userController.Activate("badkey");

            // Assert
            result.AssertResultIs <ViewResult>();
            Assert.That(_userController.ModelState.Count, Is.EqualTo(1));
        }
Exemplo n.º 15
0
        public void Activate_Should_Have_Model_Error_When_Key_Is_Invalid()
        {
            // Arrange

            // Act
            ActionResult result = _userController.Activate("badkey");

            // Assert
            result.AssertResultIs <ViewResult>();
            Assert.That(_userController.ModelState.Count, Is.EqualTo(1));
        }
Exemplo n.º 16
0
        public void activate_should_return_redirectresult_when_key_is_empty()
        {
            // Arrange + Act
            ActionResult result = _userController.Activate("");

            // Assert
            RedirectToRouteResult redirectResult = result.AssertResultIs <RedirectToRouteResult>();

            redirectResult.AssertActionRouteIs("Index");
            redirectResult.AssertControllerRouteIs("Home");
        }
Exemplo n.º 17
0
        public void Activate_Should_Return_RedirectResult_When_Key_Is_Empty()
        {
            // Arrange + Act
            ActionResult result = _userController.Activate("");

            // Assert
            RedirectToRouteResult redirectResult = result.AssertResultIs <RedirectToRouteResult>();

            redirectResult.AssertActionRouteIs("Index");
            redirectResult.AssertControllerRouteIs("Home");
        }
Exemplo n.º 18
0
        public void NotFound_Should_Return_500_View()
        {
            // Arrange

            // Act
            ActionResult result = _wikiController.NotFound();

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

            Assert.That(viewResult.ViewName, Is.EqualTo("404"));
        }
Exemplo n.º 19
0
        public void navmenu_should_return_view()
        {
            // Arrange

            // Act
            ActionResult result = _homeController.NavMenu();

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.Not.Empty);
        }
Exemplo n.º 20
0
        public void GlobalJsVars_Should_Return_View()
        {
            // Arrange

            // Act
            ActionResult result = _homeController.GlobalJsVars("2.0");

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

            viewResult.AssertViewRendered();
        }
Exemplo n.º 21
0
        public void BootstrapNavMenu_Should_Return_View()
        {
            // Arrange

            // Act
            ActionResult result = _homeController.BootstrapNavMenu();

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.Not.Empty);
        }
Exemplo n.º 22
0
        public void LeftMenu_Should_Return_Content()
        {
            // Arrange

            // Act
            ActionResult result = _homeController.LeftMenu();

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.Not.Empty);
        }
Exemplo n.º 23
0
        public void pagetoolbar_should_return_empty_content_when_id_is_null()
        {
            // Arrange

            // Act
            ActionResult result = _wikiController.PageToolbar(null);

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.Not.Null);
        }
Exemplo n.º 24
0
        public void InstallerJsVars_Should_Return_View()
        {
            // Arrange

            // Act
            ActionResult result = _installController.InstallerJsVars();

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

            viewResult.AssertViewRendered();
        }
Exemplo n.º 25
0
        public void ServerError_Should_Return_500_View()
        {
            // Arrange

            // Act
            ActionResult result = _wikiController.ServerError();

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

            Assert.That(viewResult.ViewName, Is.EqualTo("500"));
        }
Exemplo n.º 26
0
        public void Login_POST_With_Wrong_Email_And_Password_Should_Have_Model_Error()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;

            // Act
            ActionResult result = _userController.Login("wrongemail", "wrongpassword", "");

            // Assert
            result.AssertResultIs <ViewResult>();
            Assert.That(_userController.ModelState.Count, Is.EqualTo(1));
        }
Exemplo n.º 27
0
        public void Login_POST_Should_Redirect_When_Authentication_Is_Successful()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;

            // Act
            ActionResult result = _userController.Login(AdminEmail, AdminPassword, "");

            // Assert
            result.AssertResultIs <RedirectToRouteResult>();
            Assert.That(_userController.ModelState.Count, Is.EqualTo(0));
        }
Exemplo n.º 28
0
        public void login_post_with_wrong_email_and_password_should_have_model_error()
        {
            // Arrange
            _applicationSettings.UseWindowsAuthentication = false;

            // Act
            ActionResult result = _userController.Login("wrongemail", "wrongpassword", "");

            // Assert
            result.AssertResultIs <ViewResult>();
            Assert.That(_userController.ModelState.Count, Is.EqualTo(1));
        }
Exemplo n.º 29
0
        public void PageToolbar_Should_Return_Empty_Content_When_Id_Is_Null()
        {
            // Arrange

            // Act
            ActionResult result = _wikiController.PageToolbar(null);

            // Assert
            ContentResult contentResult = result.AssertResultIs <ContentResult>();

            Assert.That(contentResult.Content, Is.Not.Null);
        }
Exemplo n.º 30
0
        public void Profile_POST_Should_Redirect_If_Summary_Has_No_Id()
        {
            // Arrange
            UserViewModel model = new UserViewModel();

            // Act
            ActionResult result = _userController.Profile(model);

            // Assert
            RedirectToRouteResult redirectResult = result.AssertResultIs <RedirectToRouteResult>();

            redirectResult.AssertActionRouteIs("Login");
        }