public void IfAUrlMapsToAUrlBindingButDoesNotMatchTheWholeUrlHeldByTheBindingThenARedirectIsPerformedToTheUrlHeldByTheBinding()
        {
            var urlCache = MockRepository.GenerateStrictMock<IUrlCache>();
            var dbConnection = MockRepository.GenerateStrictMock<IDbExecutor>();

            var navigationUrlRouteHandler = new NavigationUrlRouteHandler(dbConnection, urlCache);

            var routeData = new RouteData();
            var requestContext = new RequestContext(MockRepository.GenerateMock<HttpContextBase>(), routeData);

            routeData.Values.Add("url", "ddd");

            var locatedUrlBinding = new ProductUrlBinding("aaa/bbb/ccc/ddd", "0x111/0x222/0x333/0x444");

            urlCache
                .Expect(cache => cache.TryToGetUrlBinding("ddd"))
                .Return(null);

            urlCache
                .Expect(cache => cache.StoreUrlBinding(locatedUrlBinding));

            urlCache
                .Expect(cache => cache.StoreUrlBinding(Arg<CategoryUrlBinding>.Is.NotNull))
                .Repeat
                .Times(3);

            dbConnection
                .Expect(connection => connection.Query<ProductUrlBinding>(
                    "SELECT Url As url, CompactUrl As compactUrl FROM Product WHERE Slug = 'ddd'",
                    null,
                    null,
                    true,
                    null,
                    null))
                .Return(new ProductUrlBinding[]
                {
                    locatedUrlBinding
                });

            navigationUrlRouteHandler.GetInternalTestabletHttpHandler(requestContext);

            Assert.AreEqual("product", requestContext.RouteData.Values["controller"]);
            Assert.AreEqual("redirect", requestContext.RouteData.Values["action"]);
            Assert.AreEqual(locatedUrlBinding, requestContext.RouteData.Values["urlbinding"]);

            var urlBindingsStoredInCache = urlCache
                .GetArgumentsForCallsMadeOn(cache => cache.StoreUrlBinding(null))
                .SelectMany(binding => binding)
                .Cast<UrlBinding>()
                .ToArray();

            Assert.AreEqual(locatedUrlBinding, urlBindingsStoredInCache[0]);
            Assert.AreEqual(locatedUrlBinding.AncestralUrlBindings[0].Name, urlBindingsStoredInCache[1].Name);
            Assert.AreEqual(locatedUrlBinding.AncestralUrlBindings[1].Name, urlBindingsStoredInCache[2].Name);
            Assert.AreEqual(locatedUrlBinding.AncestralUrlBindings[2].Name, urlBindingsStoredInCache[3].Name);

            urlCache.VerifyAllExpectations();
            dbConnection.VerifyAllExpectations();
        }
        public void IfAUserNavigatesToAUrlThatIsIsAValidFriendlyProductUrlAndCanBeFoundInTheCacheThenWeCanNavigateToTheUrl()
        {
            var urlCache = MockRepository.GenerateStrictMock<IUrlCache>();
            var dbConnection = MockRepository.GenerateStrictMock<IDbExecutor>();

            var navigationUrlRouteHandler = new NavigationUrlRouteHandler(dbConnection, urlCache);

            var routeData = new RouteData();
            var requestContext = new RequestContext(MockRepository.GenerateMock<HttpContextBase>(), routeData);

            routeData.Values.Add("url", "aaa/bbb/ccc/ddd");

            var locatedUrlBinding = new ProductUrlBinding("aaa/bbb/ccc/ddd", "0x111/0x222/0x333/0x444");

            urlCache
                .Expect(cache => cache.TryToGetUrlBinding("ddd"))
                .Return(locatedUrlBinding);

            navigationUrlRouteHandler.GetInternalTestabletHttpHandler(requestContext);

            Assert.AreEqual("product", requestContext.RouteData.Values["controller"]);
            Assert.AreEqual("index", requestContext.RouteData.Values["action"]);
            Assert.AreEqual(locatedUrlBinding, requestContext.RouteData.Values["urlbinding"]);

            urlCache.VerifyAllExpectations();
            dbConnection.VerifyAllExpectations();
        }