Post() private method

private Post ( ConfirmEmailForm model ) : System.Web.Mvc.ActionResult
model ConfirmEmailForm
return System.Web.Mvc.ActionResult
コード例 #1
0
            public void ReturnsRedirect_ToCreatePassword_WhenIntentMatches()
            {
                var form = new ConfirmEmailForm
                {
                    Token      = Guid.NewGuid(),
                    Intent     = EmailConfirmationIntent.CreatePassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock <IHandleCommands <RedeemEmailConfirmationCommand> >(MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))));
                var services   = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                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.CreatePassword.Name);
                routeResult.RouteValues["action"].ShouldEqual(MVC.Identity.CreatePassword.ActionNames.Get);
                routeResult.RouteValues["token"].ShouldEqual(form.Token);
            }
コード例 #2
0
            public void ReturnsView_WhenModelState_IsInvalid()
            {
                var form = new ConfirmEmailForm
                {
                    SecretCode = "wrong",
                };
                var services   = new ConfirmEmailServices(null, null);
                var controller = new ConfirmEmailController(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 <ConfirmEmailForm>();
                var model = (ConfirmEmailForm)viewResult.Model;

                model.ShouldEqual(form);
                model.Intent.ShouldEqual(form.Intent);
                model.SecretCode.ShouldEqual(form.SecretCode);
            }
コード例 #3
0
            public void Returns404_WhenModel_IsNull()
            {
                var services   = new ConfirmEmailServices(null, null);
                var controller = new ConfirmEmailController(services);

                var result = controller.Post(null);

                result.ShouldNotBeNull();
                result.ShouldBeType <HttpNotFoundResult>();
            }
コード例 #4
0
            public void ExecutesCommand_WhenAction_IsValid()
            {
                var form = new ConfirmEmailForm
                {
                    Token      = Guid.NewGuid(),
                    Intent     = EmailConfirmationIntent.ResetPassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock <IHandleCommands <RedeemEmailConfirmationCommand> >(MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))));
                var services   = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                controller.Post(form);

                commandHandler.Verify(m =>
                                      m.Handle(It.Is(ConfirmationCommandBasedOn(form))),
                                      Times.Once());
            }
コード例 #5
0
            public void FlashesSuccessMessage_ForCreatePassword_WhenIntentMatches()
            {
                var form = new ConfirmEmailForm
                {
                    Token      = Guid.NewGuid(),
                    Intent     = EmailConfirmationIntent.CreatePassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock <IHandleCommands <RedeemEmailConfirmationCommand> >(MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))));
                var services   = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                controller.Post(form);

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

                message.ShouldNotBeNull();
                message.ShouldEqual(ConfirmEmailController.SuccessMessageForIntent
                                    [EmailConfirmationIntent.CreatePassword]);
            }
コード例 #6
0
            public void SetsEmailConfirmationTicket_InTempData_UsingCommandValue()
            {
                var form = new ConfirmEmailForm
                {
                    Token      = Guid.NewGuid(),
                    Intent     = EmailConfirmationIntent.ResetPassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock <IHandleCommands <RedeemEmailConfirmationCommand> >(MockBehavior.Strict);

                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))))
                .Callback((RedeemEmailConfirmationCommand command) =>
                          command.Ticket = TwoFiftySixLengthString1);
                var services   = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                controller.Post(form);

                controller.TempData.ShouldNotBeNull();
                var ticket = controller.TempData.EmailConfirmationTicket(false);

                ticket.ShouldNotBeNull();
                ticket.ShouldEqual(TwoFiftySixLengthString1);
            }
コード例 #7
0
            public void ReturnsRedirect_ToCreatePassword_WhenIntentMatches()
            {
                var form = new ConfirmEmailForm
                {
                    Token = Guid.NewGuid(),
                    Intent = EmailConfirmationIntent.CreatePassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock<IHandleCommands<RedeemEmailConfirmationCommand>>(MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))));
                var services = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                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.CreatePassword.Name);
                routeResult.RouteValues["action"].ShouldEqual(MVC.Identity.CreatePassword.ActionNames.Get);
                routeResult.RouteValues["token"].ShouldEqual(form.Token);
            }
コード例 #8
0
            public void FlashesSuccessMessage_ForCreatePassword_WhenIntentMatches()
            {
                var form = new ConfirmEmailForm
                {
                    Token = Guid.NewGuid(),
                    Intent = EmailConfirmationIntent.CreatePassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock<IHandleCommands<RedeemEmailConfirmationCommand>>(MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))));
                var services = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                controller.Post(form);

                controller.TempData.ShouldNotBeNull();
                var message = controller.TempData.FeedbackMessage();
                message.ShouldNotBeNull();
                message.ShouldEqual(ConfirmEmailController.SuccessMessageForIntent
                    [EmailConfirmationIntent.CreatePassword]);
            }
コード例 #9
0
            public void SetsEmailConfirmationTicket_InTempData_UsingCommandValue()
            {
                var form = new ConfirmEmailForm
                {
                    Token = Guid.NewGuid(),
                    Intent = EmailConfirmationIntent.ResetPassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock<IHandleCommands<RedeemEmailConfirmationCommand>>(MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))))
                    .Callback((RedeemEmailConfirmationCommand command) =>
                        command.Ticket = TwoFiftySixLengthString1);
                var services = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                controller.Post(form);

                controller.TempData.ShouldNotBeNull();
                var ticket = controller.TempData.EmailConfirmationTicket(false);
                ticket.ShouldNotBeNull();
                ticket.ShouldEqual(TwoFiftySixLengthString1);
            }
コード例 #10
0
            public void ExecutesCommand_WhenAction_IsValid()
            {
                var form = new ConfirmEmailForm
                {
                    Token = Guid.NewGuid(),
                    Intent = EmailConfirmationIntent.ResetPassword,
                    SecretCode = "secret",
                };
                var commandHandler = new Mock<IHandleCommands<RedeemEmailConfirmationCommand>>(MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(ConfirmationCommandBasedOn(form))));
                var services = new ConfirmEmailServices(null, commandHandler.Object);
                var controller = new ConfirmEmailController(services);

                controller.Post(form);

                commandHandler.Verify(m =>
                    m.Handle(It.Is(ConfirmationCommandBasedOn(form))),
                        Times.Once());
            }
コード例 #11
0
            public void ReturnsView_WhenModelState_IsInvalid()
            {
                var form = new ConfirmEmailForm
                {
                    SecretCode = "wrong",
                };
                var services = new ConfirmEmailServices(null, null);
                var controller = new ConfirmEmailController(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<ConfirmEmailForm>();
                var model = (ConfirmEmailForm)viewResult.Model;
                model.ShouldEqual(form);
                model.Intent.ShouldEqual(form.Intent);
                model.SecretCode.ShouldEqual(form.SecretCode);
            }
コード例 #12
0
            public void Returns404_WhenModel_IsNull()
            {
                var services = new ConfirmEmailServices(null, null);
                var controller = new ConfirmEmailController(services);

                var result = controller.Post(null);

                result.ShouldNotBeNull();
                result.ShouldBeType<HttpNotFoundResult>();
            }