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 SetsModelProperty_IsUrlConfirmation_ToTrue_WhenMethodArgIsNotNullOrWhiteSpace() { var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword) { SecretCode = "very secret", }; const string secretCode = "not as secret"; var queryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict); queryProcessor.Setup(m => m.Execute(It.Is(ConfirmationQueryBasedOn(confirmation.Token)))) .Returns(confirmation); var services = new ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); var result = controller.Get(confirmation.Token, secretCode); result.ShouldNotBeNull(); result.ShouldImplement <ViewResultBase>(); var viewResultBase = (ViewResultBase)result; viewResultBase.Model.ShouldNotBeNull(); viewResultBase.Model.ShouldBeType <ConfirmEmailForm>(); var model = (ConfirmEmailForm)viewResultBase.Model; model.SecretCode.ShouldEqual(secretCode); model.SecretCode.ShouldNotEqual(confirmation.SecretCode); model.IsUrlConfirmation.ShouldBeTrue(); }
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 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 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 ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); var result = controller.Get(token, null); result.ShouldNotBeNull(); result.ShouldBeType <HttpNotFoundResult>(); }
public void ReturnsView_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 ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); var result = controller.Get(confirmation.Token, null); result.ShouldNotBeNull(); result.ShouldBeType <ViewResult>(); }
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 ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); controller.Get(token, null); queryProcessor.Verify(m => m.Execute( It.Is(ConfirmationQueryBasedOn(token))), Times.Once()); }
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 ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); controller.Get(token, null); queryProcessor.Verify(m => m.Execute( It.Is(ConfirmationQueryBasedOn(token))), Times.Once()); }
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 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 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 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 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 SetsModelProperty_IsUrlConfirmation_ToTrue_WhenMethodArgIsNotNullOrWhiteSpace() { var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword) { SecretCode = "very secret", }; const string secretCode = "not as secret"; var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict); queryProcessor.Setup(m => m.Execute(It.Is(ConfirmationQueryBasedOn(confirmation.Token)))) .Returns(confirmation); var services = new ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); var result = controller.Get(confirmation.Token, secretCode); result.ShouldNotBeNull(); result.ShouldImplement<ViewResultBase>(); var viewResultBase = (ViewResultBase)result; viewResultBase.Model.ShouldNotBeNull(); viewResultBase.Model.ShouldBeType<ConfirmEmailForm>(); var model = (ConfirmEmailForm)viewResultBase.Model; model.SecretCode.ShouldEqual(secretCode); model.SecretCode.ShouldNotEqual(confirmation.SecretCode); model.IsUrlConfirmation.ShouldBeTrue(); }
public ConfirmEmailController(ConfirmEmailServices services) { _services = services; }
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 ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); var result = controller.Get(token, null); result.ShouldNotBeNull(); result.ShouldBeType<HttpNotFoundResult>(); }
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 ReturnsView_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 ConfirmEmailServices(queryProcessor.Object, null); var controller = new ConfirmEmailController(services); var result = controller.Get(confirmation.Token, null); result.ShouldNotBeNull(); result.ShouldBeType<ViewResult>(); }