private Post ( ConfirmEmailForm model ) : System.Web.Mvc.ActionResult | ||
model | ConfirmEmailForm | |
return | System.Web.Mvc.ActionResult |
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 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>(); }
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 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 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>(); }