public void BaseControllerRedirectBackActuallyRedirects()
        {
            // prepare
            var context = HttpMocks.GetControllerContextMock().Object;
            var contr = new UnprotectedBase { ControllerContext = context };

            // act
            var result = contr.RedirectBack();

            // assert
            result.Should().BeOfType<RedirectToRouteResult>();
        }
        public void BaseControllerRedirectBackAllEmptyGoesToHomeIndex()
        {
            // prepare
            var session = new HttpSessionMock();
            var context = HttpMocks.GetControllerContextMock(HttpMocks.GetHttpContextMock(sessionMock: session)).Object;
            var contr = new UnprotectedBase { ControllerContext = context };

            // act
            var result = contr.RedirectBack();

            // assert
            result.Should().BeRedirectToRouteResult().WithController("home").WithAction("index");
            result.As<RedirectToRouteResult>().RouteValues.Should().NotContainKey("id");
        }
        public void BaseControllerRedirectBackNoParmsGoesToSessionControllerActionId()
        {
            // prepare
            var session = new HttpSessionMock();
            session["ReturnControllerAction"] = new ReturnControllerActionIdentifier
            {
                ControllerName = "TestableCtr",
                ActionName = "TestAction",
                EntityId = "123456-654321",
                BookmarkTag = null
            };
            var context = HttpMocks.GetControllerContextMock(HttpMocks.GetHttpContextMock(sessionMock: session)).Object;
            var contr = new UnprotectedBase { ControllerContext = context };

            // act
            var result = contr.RedirectBack();

            // assert
            result.As<RedirectToRouteResult>().RouteValues.Should().ContainKeys("controller", "action", "id");
            result.As<RedirectToRouteResult>().RouteValues["controller"].Should().Be("TestableCtr");
            result.As<RedirectToRouteResult>().RouteValues["action"].Should().Be("TestAction");
            result.As<RedirectToRouteResult>().RouteValues["id"].Should().Be("123456-654321");
        }
        public void BaseControllerStoringReturnPathGoesToSession()
        {
            // prepare
            var session = new HttpSessionMock();
            var contr = new UnprotectedBase();
            var context = HttpMocks.GetControllerContextMock(HttpMocks.GetHttpContextMock(sessionMock: session), controller: contr).Object;
            contr.ControllerContext = context;

            // act (controller, action & id are set in HttpMocks helper)
            contr.StoreReturnRoute("SandboxTag");

            // assert ReturnRoute
            session.Keys.Count().Should().Be(1);
            session.Keys.Contains("ReturnControllerAction").Should().BeTrue();
            session["ReturnControllerAction"].As<ReturnControllerActionIdentifier>().ControllerName.Should().Be("SandboxTest");
            session["ReturnControllerAction"].As<ReturnControllerActionIdentifier>().ActionName.Should().Be("SandboxAction");
            session["ReturnControllerAction"].As<ReturnControllerActionIdentifier>().EntityId.Should().Be("1223334444-abcdef");
            session["ReturnControllerAction"].As<ReturnControllerActionIdentifier>().BookmarkTag.Should().Be("SandboxTag");
        }
        public void BaseControllerRedirectBackWithParmTagStoresTag()
        {
            // prepare
            var session = new HttpSessionMock();
            session["ReturnControllerAction"] = new ReturnControllerActionIdentifier
            {
                ControllerName = "FallbackCtr",
                ActionName = "FallbackAction",
                EntityId = "abcdef123",
                BookmarkTag = "FallbackTag"
            };

            var contr = new UnprotectedBase();
            var context = HttpMocks.GetControllerContextMock(HttpMocks.GetHttpContextMock(sessionMock: session), controller: contr).Object;
            contr.ControllerContext = context;

            // act
            var result = contr.RedirectBack("DirectedCtrl", "DirectedAction", "505050", "DirectTag");

            // assert
            contr.TempData.Should().ContainKey("bookmarkTag");
            contr.TempData["bookmarkTag"].Should().Be("DirectTag");
        }
        public void BaseControllerRedirectBackWithParmsGoesToSpecifiedControllerIndex()
        {
            // prepare
            var session = new HttpSessionMock();
            session["ReturnControllerAction"] = new ReturnControllerActionIdentifier
            {
                ControllerName = "FallbackCtr",
                ActionName = "FallbackAction",
                EntityId = "abcdef123",
                BookmarkTag = "FallbackTag"
            };
            var context = HttpMocks.GetControllerContextMock(HttpMocks.GetHttpContextMock(sessionMock: session)).Object;
            var contr = new UnprotectedBase { ControllerContext = context };

            // act
            var result = contr.RedirectBack("DirectedCtrl");

            // assert
            result.As<RedirectToRouteResult>().RouteValues.Should().ContainKeys("controller", "action");
            result.As<RedirectToRouteResult>().RouteValues.Should().NotContainKey("id");
            result.As<RedirectToRouteResult>().RouteValues["controller"].Should().Be("DirectedCtrl");
            result.As<RedirectToRouteResult>().RouteValues["action"].Should().Be("Index");
        }
        public void BaseControllerRedirectBackNoParmsGoesToSessionControllerIndex()
        {
            // prepare
            var session = new HttpSessionMock();
            session["ReturnControllerAction"] = new ReturnControllerActionIdentifier
            {
                ControllerName = "TestableCtr",
                ActionName = null,
                EntityId = null,
                BookmarkTag = null
            };
            var context = HttpMocks.GetControllerContextMock(HttpMocks.GetHttpContextMock(sessionMock: session)).Object;
            var contr = new UnprotectedBase { ControllerContext = context };

            // act
            var result = contr.RedirectBack();

            // assert
            result.Should().BeRedirectToRouteResult().WithController("TestableCtr").WithAction("Index");
            result.As<RedirectToRouteResult>().RouteValues.Should().NotContainKey("id");
        }