public void UrlBinderReturnsANewCategoryUrlBinding() { var urlBindingBinder = new UrlBindingBinder(); var expected = new CategoryUrlBinding(); var routeData = new RouteData(); routeData.Values.Add("urlbinding", expected); Assert.AreEqual(expected, urlBindingBinder.BindModel(new ControllerContext { RouteData = routeData }, null)); }
public void IfAUserNavigatesToAUrlThatIsIsAValidFriendlyCategoryUrlAndCanBeFoundInTheCacheThenWeCanNavigateToTheUrl() { 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 CategoryUrlBinding("aaa/bbb/ccc/ddd", "0x111/0x222/0x333/0x444"); urlCache .Expect(cache => cache.TryToGetUrlBinding("ddd")) .Return(locatedUrlBinding); navigationUrlRouteHandler.GetInternalTestabletHttpHandler(requestContext); Assert.AreEqual("category", requestContext.RouteData.Values["controller"]); Assert.AreEqual("index", requestContext.RouteData.Values["action"]); Assert.AreEqual(locatedUrlBinding, requestContext.RouteData.Values["urlbinding"]); urlCache.VerifyAllExpectations(); dbConnection.VerifyAllExpectations(); }
public void IfAUserNavigatesToAUrlThatIsIsAValidFriendlyCategoryUrlAndCanBeFoundInTheDatabaseAndNotInTheCacheThenItIsCachedAndWeNavigateToTheUrl() { 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 CategoryUrlBinding("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[] { }); dbConnection .Expect(connection => connection.Query<CategoryUrlBinding>( "SELECT Url As url, CompactUrl As compactUrl FROM Category WHERE Slug = 'ddd'", null, null, true, null, null)) .Return(new CategoryUrlBinding[] { locatedUrlBinding }); navigationUrlRouteHandler.GetInternalTestabletHttpHandler(requestContext); Assert.AreEqual("category", requestContext.RouteData.Values["controller"]); Assert.AreEqual("index", requestContext.RouteData.Values["action"]); Assert.AreEqual(locatedUrlBinding, requestContext.RouteData.Values["urlbinding"]); var urlBindingsStoredInCache = urlCache .GetArgumentsForCallsMadeOn(cache => cache.StoreUrlBinding(null)) .SelectMany(binding => binding) .Cast<CategoryUrlBinding>() .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(); }