예제 #1
0
        public void Register_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // Arrange
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "Dummy error message.");

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            Assert.That(result, Is.InstanceOf(typeof(ViewResult)));
            ViewResult viewResult = (ViewResult)result;
            Assert.That(viewResult.ViewData.Model, Is.EqualTo(model));
            Assert.That(viewResult.ViewData["PasswordLength"], Is.EqualTo(10));
        }
예제 #2
0
        public void Register_Post_ReturnsViewIfRegistrationFails()
        {
            // Arrange
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            Assert.That(result, Is.InstanceOf(typeof(ViewResult)));
            ViewResult viewResult = (ViewResult)result;
            Assert.That(viewResult.ViewData.Model, Is.EqualTo(model));
            Assert.That(controller.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("Username already exists. Please enter a different user name."));
            Assert.That(viewResult.ViewData["PasswordLength"], Is.EqualTo(10));
        }
예제 #3
0
        public void Register_Post_ReturnsRedirectOnSuccess()
        {
            // Arrange
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            Assert.That(result, Is.InstanceOf(typeof(RedirectToRouteResult)));
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.That(redirectResult.RouteValues["controller"], Is.EqualTo("Home"));
            Assert.That(redirectResult.RouteValues["action"], Is.EqualTo("Index"));
        }