public void FlashesSuccessMessage()
            {
                var form = new ResetPasswordForm
                {
                    Token                = Guid.NewGuid(),
                    Password             = "******",
                    PasswordConfirmation = "password",
                };
                var commandHandler = new Mock <IHandleCommands <ResetPasswordCommand> >
                                         (MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ResetCommandBasedOn(form, TwoFiftySixLengthString1))));
                var services   = new ResetPasswordServices(null, commandHandler.Object);
                var controller = new ResetPasswordController(services);

                controller.TempData.EmailConfirmationTicket(TwoFiftySixLengthString1);

                controller.Post(form);

                controller.TempData.ShouldNotBeNull();
                var message = controller.TempData.FeedbackMessage();

                message.ShouldNotBeNull();
                message.ShouldEqual(ResetPasswordController.SuccessMessage);
            }
            public void ReturnsRedirect_ToSignIn()
            {
                var form = new ResetPasswordForm
                {
                    Token                = Guid.NewGuid(),
                    Password             = "******",
                    PasswordConfirmation = "password",
                };
                var commandHandler = new Mock <IHandleCommands <ResetPasswordCommand> >
                                         (MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ResetCommandBasedOn(form, TwoFiftySixLengthString2))));
                var services   = new ResetPasswordServices(null, commandHandler.Object);
                var controller = new ResetPasswordController(services);

                controller.TempData.EmailConfirmationTicket(TwoFiftySixLengthString2);

                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.SignIn.Name);
                routeResult.RouteValues["action"].ShouldEqual(MVC.Identity.SignIn.ActionNames.Get);
            }
            public void Returns404_WhenModel_IsNull()
            {
                var services   = new ResetPasswordServices(null, null);
                var controller = new ResetPasswordController(services);

                var result = controller.Post(null);

                result.ShouldNotBeNull();
                result.ShouldBeType <HttpNotFoundResult>();
            }
            public void Returns404_WhenConfirmation_CannotBeFound()
            {
                var token          = Guid.NewGuid();
                var queryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

                queryProcessor.Setup(m => m.Execute(It.Is(ConfirmationQueryBasedOn(token))))
                .Returns(null as EmailConfirmation);
                var services   = new ResetPasswordServices(queryProcessor.Object, null);
                var controller = new ResetPasswordController(services);

                var result = controller.Get(token);

                result.ShouldNotBeNull();
                result.ShouldBeType <HttpNotFoundResult>();
            }
            public void ExecutesQuery_ForConfirmation()
            {
                var token          = Guid.NewGuid();
                var queryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

                queryProcessor.Setup(m => m.Execute(It.Is(ConfirmationQueryBasedOn(token))))
                .Returns(null as EmailConfirmation);
                var services   = new ResetPasswordServices(queryProcessor.Object, null);
                var controller = new ResetPasswordController(services);

                controller.Get(token);

                queryProcessor.Verify(m => m.Execute(
                                          It.Is(ConfirmationQueryBasedOn(token))),
                                      Times.Once());
            }
            public void ExecutesCommand_WhenAction_IsValid()
            {
                var form = new ResetPasswordForm
                {
                    Token = Guid.NewGuid(),
                };
                var commandHandler = new Mock <IHandleCommands <ResetPasswordCommand> >
                                         (MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ResetCommandBasedOn(form, TwoFiftySixLengthString1))));
                var services   = new ResetPasswordServices(null, commandHandler.Object);
                var controller = new ResetPasswordController(services);

                controller.TempData.EmailConfirmationTicket(TwoFiftySixLengthString1);

                controller.Post(form);

                commandHandler.Verify(m =>
                                      m.Handle(It.Is(ResetCommandBasedOn(form, TwoFiftySixLengthString1))),
                                      Times.Once());
            }
            public void ClearsTempDataValue_Ticket()
            {
                var form = new ResetPasswordForm
                {
                    Token                = Guid.NewGuid(),
                    Password             = "******",
                    PasswordConfirmation = "password",
                };
                var commandHandler = new Mock <IHandleCommands <ResetPasswordCommand> >
                                         (MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ResetCommandBasedOn(form, TwoFiftySixLengthString3))));
                var services   = new ResetPasswordServices(null, commandHandler.Object);
                var controller = new ResetPasswordController(services);

                controller.TempData.EmailConfirmationTicket(TwoFiftySixLengthString3);
                controller.TempData.EmailConfirmationTicket().ShouldNotBeNull();

                controller.Post(form);

                controller.TempData.EmailConfirmationTicket().ShouldBeNull();
            }
            public void SetsCommandValue_Ticket_UsingTempDataValue()
            {
                var form = new ResetPasswordForm
                {
                    Token                = Guid.NewGuid(),
                    Password             = "******",
                    PasswordConfirmation = "password",
                };
                ResetPasswordCommand outCommand = null;
                var commandHandler = new Mock <IHandleCommands <ResetPasswordCommand> >
                                         (MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ResetCommandBasedOn(form, TwoFiftySixLengthString2))))
                .Callback((ResetPasswordCommand command) => outCommand = command);
                var services   = new ResetPasswordServices(null, commandHandler.Object);
                var controller = new ResetPasswordController(services);

                controller.TempData.EmailConfirmationTicket(TwoFiftySixLengthString2);

                controller.Post(form);

                outCommand.Ticket.ShouldEqual(TwoFiftySixLengthString2);
            }
            public void ReturnsView_WhenModelState_IsInvalid()
            {
                var form = new ResetPasswordForm
                {
                    Token = Guid.NewGuid(),
                };
                var services   = new ResetPasswordServices(null, null);
                var controller = new ResetPasswordController(services);

                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 <ResetPasswordForm>();
                var model = (ResetPasswordForm)viewResult.Model;

                model.ShouldEqual(form);
                model.Token.ShouldEqual(form.Token);
            }
            public void ReturnsView_WithModel_WhenConfirmation_IsFound()
            {
                var confirmation   = new EmailConfirmation(EmailConfirmationIntent.CreatePassword);
                var queryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

                queryProcessor.Setup(m => m.Execute(It.Is(ConfirmationQueryBasedOn(confirmation.Token))))
                .Returns(confirmation);
                var services   = new ResetPasswordServices(queryProcessor.Object, null);
                var controller = new ResetPasswordController(services);

                var result = controller.Get(confirmation.Token);

                result.ShouldNotBeNull();
                result.ShouldBeType <ViewResult>();
                var viewResult = (ViewResult)result;

                viewResult.Model.ShouldNotBeNull();
                viewResult.Model.ShouldBeType <ResetPasswordForm>();
                var model = (ResetPasswordForm)viewResult.Model;

                model.Token.ShouldEqual(confirmation.Token);
                model.Password.ShouldBeNull();
                model.PasswordConfirmation.ShouldBeNull();
            }