Esempio n. 1
0
            public void ReturnsRedirect_ToModelReturnUrl_AfterCommandIsExecuted()
            {
                const int    number                = 2;
                const string personUserName        = "******";
                const string newValue              = "*****@*****.**";
                const string principalIdentityName = "*****@*****.**";
                var          scenarioOptions       = new ScenarioOptions
                {
                    PrincipalIdentityName = principalIdentityName,
                };
                var model = new UpdateEmailValueForm
                {
                    Number         = number,
                    PersonUserName = personUserName,
                    Value          = newValue,
                    ReturnUrl      = "https://www.site.com/"
                };
                var controller = CreateController(scenarioOptions);
                var builder    = ReuseMock.TestControllerBuilder();
                var principal  = principalIdentityName.AsPrincipal();

                builder.HttpContext.User = principal;
                builder.InitializeController(controller);
                scenarioOptions.MockCommandHandler.Setup(m => m.Handle(It.Is(CommandBasedOn(model))));

                var result = controller.Put(model);

                result.ShouldNotBeNull();
                result.ShouldBeType <RedirectResult>();
                var redirectResult = (RedirectResult)result;

                redirectResult.Url.ShouldEqual(model.ReturnUrl);
                redirectResult.Permanent.ShouldBeFalse();
            }
Esempio n. 2
0
        private static UpdateEmailValueController CreateController(ScenarioOptions scenarioOptions = null)
        {
            scenarioOptions = scenarioOptions ?? new ScenarioOptions();

            scenarioOptions.MockQueryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

            scenarioOptions.MockCommandHandler = new Mock <IHandleCommands <UpdateMyEmailValueCommand> >(MockBehavior.Strict);

            var services = new UpdateEmailValueServices(scenarioOptions.MockQueryProcessor.Object, scenarioOptions.MockCommandHandler.Object);

            var controller = new UpdateEmailValueController(services);

            var builder = ReuseMock.TestControllerBuilder();

            builder.HttpContext.User = null;
            if (!string.IsNullOrWhiteSpace(scenarioOptions.PrincipalIdentityName))
            {
                var principal = scenarioOptions.PrincipalIdentityName.AsPrincipal();
                builder.HttpContext.User = principal;
            }

            builder.InitializeController(controller);

            return(controller);
        }
Esempio n. 3
0
            public void ExecutesCommand_WhenAction_IsValid()
            {
                const int    number                = 2;
                const string personUserName        = "******";
                const string newValue              = "*****@*****.**";
                const string principalIdentityName = "*****@*****.**";
                var          scenarioOptions       = new ScenarioOptions
                {
                    PrincipalIdentityName = principalIdentityName,
                };
                var model = new UpdateEmailValueForm
                {
                    Number         = number,
                    PersonUserName = personUserName,
                    Value          = newValue,
                    ReturnUrl      = "https://www.site.com/"
                };
                var controller = CreateController(scenarioOptions);
                var builder    = ReuseMock.TestControllerBuilder();
                var principal  = principalIdentityName.AsPrincipal();

                builder.HttpContext.User = principal;
                builder.InitializeController(controller);
                scenarioOptions.MockCommandHandler.Setup(m => m.Handle(It.Is(CommandBasedOn(model))));

                controller.Put(model);

                scenarioOptions.MockCommandHandler.Verify(m =>
                                                          m.Handle(It.Is(CommandBasedOn(model))),
                                                          Times.Once());
            }
Esempio n. 4
0
            public void FlashesNoChangesMessage_WhenCommand_ChangedState()
            {
                const int    number                = 2;
                const string personUserName        = "******";
                const string newValue              = "*****@*****.**";
                const string principalIdentityName = "*****@*****.**";
                var          scenarioOptions       = new ScenarioOptions
                {
                    PrincipalIdentityName = principalIdentityName,
                };
                var model = new UpdateEmailValueForm
                {
                    Number         = number,
                    PersonUserName = personUserName,
                    Value          = newValue,
                    ReturnUrl      = "https://www.site.com/"
                };
                var controller = CreateController(scenarioOptions);
                var builder    = ReuseMock.TestControllerBuilder();
                var principal  = principalIdentityName.AsPrincipal();

                builder.HttpContext.User = principal;
                builder.InitializeController(controller);
                scenarioOptions.MockCommandHandler.Setup(m => m.Handle(It.Is(CommandBasedOn(model))));

                controller.Put(model);

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

                message.ShouldNotBeNull();
                message.ShouldEqual(UpdateEmailValueController.NoChangesMessage);
            }
            public void ReturnsView_WhenReturnUrlArg_IsNonEmptyString()
            {
                const string returnUrl  = "/path/to/resource";
                var          userSigner = new Mock <ISignUsers>(MockBehavior.Strict);

                userSigner.Setup(p => p.DefaultSignedOnUrl).Returns("/my/home");
                var services       = CreateSignOnServices();
                var builder        = ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper);
                var requestContext = new RequestContext(builder.HttpContext, new RouteData());
                var controller     = new SignOnController(services)
                {
                    Url = new UrlHelper(requestContext)
                };

                var result = controller.Get(returnUrl);

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

                viewResult.ViewName.ShouldEqual(string.Empty);
                viewResult.Model.ShouldNotBeNull();
                viewResult.Model.ShouldBeType <SignOnForm>();
                var form = (SignOnForm)viewResult.Model;

                form.EmailAddress.ShouldBeNull();
                form.ReturnUrl.ShouldEqual(returnUrl);
            }
Esempio n. 6
0
            public void ReturnsRedirect_ToConfirmEmail_WithCommandToken()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var commandHandler = new Mock<IHandleCommands<SendConfirmEmailMessageCommand>>
                    (MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(SendCommandBasedOn(form))));
                var services = new ForgotPasswordServices(commandHandler.Object);
                var controller = new ForgotPasswordController(services);
                ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper)
                    .InitializeController(controller);

                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.ConfirmEmail.Name);
                routeResult.RouteValues["action"].ShouldEqual(MVC.Identity.ConfirmEmail.ActionNames.Get);
                routeResult.RouteValues["token"].ShouldEqual(Guid.Empty);
            }
Esempio n. 7
0
            public void ExecutesCommand_WhenAction_IsValid()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var commandHandler = new Mock<IHandleCommands<SendConfirmEmailMessageCommand>>
                    (MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(SendCommandBasedOn(form))));
                var services = new ForgotPasswordServices(commandHandler.Object);
                var controller = new ForgotPasswordController(services);
                ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper)
                    .InitializeController(controller);

                controller.Post(form);

                commandHandler.Verify(m =>
                    m.Handle(It.Is(SendCommandBasedOn(form))),
                        Times.Once());
            }
        private static MyHomeController CreateController(ScenarioOptions scenarioOptions = null)
        {
            scenarioOptions = scenarioOptions ?? new ScenarioOptions();

            scenarioOptions.MockQueryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

            var services = new MyHomeServices(scenarioOptions.MockQueryProcessor.Object);

            var controller = new MyHomeController(services);

            var builder = ReuseMock.TestControllerBuilder();

            builder.HttpContext.User = null;
            if (!string.IsNullOrWhiteSpace(scenarioOptions.PrincipalIdentityName))
            {
                builder.HttpContext.User = scenarioOptions.PrincipalIdentityName.AsPrincipal();
            }

            builder.InitializeController(controller);

            return(controller);
        }
Esempio n. 9
0
            public void FlashesSuccessMessage_UsingModelProperty_EmailAddress()
            {
                var form = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var commandHandler = new Mock<IHandleCommands<SendConfirmEmailMessageCommand>>
                    (MockBehavior.Strict);
                commandHandler.Setup(m => m.Handle(It.Is(SendCommandBasedOn(form))));
                var services = new ForgotPasswordServices(commandHandler.Object);
                var controller = new ForgotPasswordController(services);
                ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper)
                    .InitializeController(controller);

                controller.Post(form);

                controller.TempData.ShouldNotBeNull();
                var message = controller.TempData.FeedbackMessage();
                message.ShouldNotBeNull();
                message.ShouldEqual(string.Format(
                    ForgotPasswordController.SuccessMessageFormat,
                        form.EmailAddress));
            }
            public void ReturnsView_WhenReturnUrlArg_IsNull()
            {
                var services       = CreateSignOnServices();
                var builder        = ReuseMock.TestControllerBuilder(ControllerCustomization.ForUrlHelper);
                var requestContext = new RequestContext(builder.HttpContext, new RouteData());
                var controller     = new SignOnController(services)
                {
                    Url = new UrlHelper(requestContext)
                };

                var result = controller.Get(null);

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

                viewResult.ViewName.ShouldEqual(string.Empty);
                viewResult.Model.ShouldNotBeNull();
                viewResult.Model.ShouldBeType <SignOnForm>();
                var form = (SignOnForm)viewResult.Model;

                form.EmailAddress.ShouldBeNull();
                form.ReturnUrl.ShouldBeNull();
            }
        private static UpdateNameController CreateController(ScenarioOptions scenarioOptions = null)
        {
            scenarioOptions = scenarioOptions ?? new ScenarioOptions();

            scenarioOptions.MockQueryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict);

            scenarioOptions.MockCommandHandler = new Mock <IHandleCommands <UpdateMyNameCommand> >(MockBehavior.Strict);

            var services = new UpdateNameServices(scenarioOptions.MockQueryProcessor.Object, scenarioOptions.MockCommandHandler.Object);

            var controller = new UpdateNameController(services);

            var builder = ReuseMock.TestControllerBuilder();

            if (!string.IsNullOrWhiteSpace(scenarioOptions.PrincipalIdentityName))
            {
                builder.HttpContext.User = scenarioOptions.PrincipalIdentityName.AsPrincipal();
            }

            builder.InitializeController(controller);

            if (scenarioOptions.IsChildAction)
            {
                var controllerContext = new Mock <ControllerContext>(MockBehavior.Strict);
                var parentContext     = new ViewContext {
                    TempData = new TempDataDictionary()
                };
                builder.RouteData.DataTokens.Add("ParentActionViewContext", parentContext);
                controllerContext.Setup(p => p.IsChildAction).Returns(true);
                controllerContext.Setup(p => p.HttpContext).Returns(builder.HttpContext);
                controllerContext.Setup(p => p.RouteData).Returns(builder.RouteData);
                controller.ControllerContext = controllerContext.Object;
            }

            return(controller);
        }