Post() приватный Метод

private Post ( ConfirmEmailForm model ) : System.Web.Mvc.ActionResult
model ConfirmEmailForm
Результат 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);
            }
            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);
            }
            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]);
            }
            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);
            }
            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());
            }
            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);
            }
            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>();
            }