Beispiel #1
0
            public void ReturnsRedirect_ToConfirmEmail_WithCommandToken()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var commandHandler = new Mock<IHandleCommands<SendConfirmEmailMessageCommand>>
                    (MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(SendCommandBasedOn(form))));
                var services = new ForgotPasswordServices(commandHandler.Object);
                var controller = new ForgotPasswordController(services);
                ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper)
                    .InitializeController(controller);

                var result = controller.Post(form);

                result.ShouldNotBeNull();
                result.ShouldBeType<RedirectToRouteResult>();
                var routeResult = (RedirectToRouteResult)result;
                routeResult.Permanent.ShouldBeFalse();
                routeResult.RouteValues["area"].ShouldEqual(MVC.Identity.Name);
                routeResult.RouteValues["controller"].ShouldEqual(MVC.Identity.ConfirmEmail.Name);
                routeResult.RouteValues["action"].ShouldEqual(MVC.Identity.ConfirmEmail.ActionNames.Get);
                routeResult.RouteValues["token"].ShouldEqual(Guid.Empty);
            }
Beispiel #2
0
            public void Returns404_WhenModel_IsNull()
            {
                var controller = new ForgotPasswordController(null);

                var result = controller.Post(null);

                result.ShouldNotBeNull();
                result.ShouldBeType<HttpNotFoundResult>();
            }
Beispiel #3
0
            public void ReturnsPartialView_WithEmptyModel()
            {
                var controller = new ForgotPasswordController(null);

                var result = controller.Get();

                result.ShouldNotBeNull();
                result.Model.ShouldNotBeNull();
                result.Model.ShouldBeType<ForgotPasswordForm>();
                var model = (ForgotPasswordForm)result.Model;
                model.EmailAddress.ShouldBeNull();
            }
Beispiel #4
0
            public void ExecutesCommand_WhenAction_IsValid()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var commandHandler = new Mock<IHandleCommands<SendConfirmEmailMessageCommand>>
                    (MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(SendCommandBasedOn(form))));
                var services = new ForgotPasswordServices(commandHandler.Object);
                var controller = new ForgotPasswordController(services);
                ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper)
                    .InitializeController(controller);

                controller.Post(form);

                commandHandler.Verify(m =>
                    m.Handle(It.Is(SendCommandBasedOn(form))),
                        Times.Once());
            }
Beispiel #5
0
            public void ReturnView_WhenModelState_IsInvalid()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "wrong",
                };
                var controller = new ForgotPasswordController(null);
                controller.ModelState.AddModelError("error", string.Empty);

                var result = controller.Post(form);

                result.ShouldNotBeNull();
                result.ShouldBeType<ViewResult>();
                var viewResult = (ViewResult)result;
                viewResult.Model.ShouldNotBeNull();
                viewResult.Model.ShouldBeType<ForgotPasswordForm>();
                var model = (ForgotPasswordForm)viewResult.Model;
                model.ShouldEqual(form);
                model.EmailAddress.ShouldEqual(form.EmailAddress);
            }
Beispiel #6
0
            public void FlashesSuccessMessage_UsingModelProperty_EmailAddress()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var commandHandler = new Mock<IHandleCommands<SendConfirmEmailMessageCommand>>
                    (MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(SendCommandBasedOn(form))));
                var services = new ForgotPasswordServices(commandHandler.Object);
                var controller = new ForgotPasswordController(services);
                ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper)
                    .InitializeController(controller);

                controller.Post(form);

                controller.TempData.ShouldNotBeNull();
                var message = controller.TempData.FeedbackMessage();
                message.ShouldNotBeNull();
                message.ShouldEqual(string.Format(
                    ForgotPasswordController.SuccessMessageFormat,
                        form.EmailAddress));
            }
Beispiel #7
0
 public void Extends_BaseController()
 {
     var controller = new ForgotPasswordController(null);
     controller.ShouldImplement<BaseController>();
 }