Exemplo n.º 1
0
        public void Match_Document_By_Url(string urlString, int expectedId)
        {
            var routingContext = GetRoutingContext(urlString);
            var url            = routingContext.UmbracoContext.CleanedUmbracoUrl;       //very important to use the cleaned up umbraco url
            var docreq         = new PublishedContentRequest(url, routingContext);
            var lookup         = new LookupByNiceUrl();

            var result = lookup.TrySetDocument(docreq);

            Assert.IsTrue(result);
            Assert.AreEqual(expectedId, docreq.DocumentId);
        }
Exemplo n.º 2
0
        public void DoNotPolluteCache()
        {
            SettingsForTests.UseDirectoryUrls         = true;
            SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
            SettingsForTests.UseDomainPrefixes        = false;

            InitializeLanguagesAndDomains();
            SetDomains1();

            RoutingContext routingContext;
            string         url = "http://domain1.com/1001-1/1001-1-1";

            // get the nice url for 100111
            routingContext = GetRoutingContext(url);
            Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111, true));

            // check that the proper route has been cached
            var cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes();

            Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]);

            // route a rogue url
            url = "http://domain1.com/1001-1/1001-1-1";
            var uri     = routingContext.UmbracoContext.CleanedUmbracoUrl;         //very important to use the cleaned up umbraco url
            var docreq  = new PublishedContentRequest(uri, routingContext);
            var builder = new PublishedContentRequestBuilder(docreq);

            builder.LookupDomain();
            Assert.IsTrue(docreq.HasDomain);

            // check that it's been routed
            var lookup = new LookupByNiceUrl();
            var result = lookup.TrySetDocument(docreq);

            Assert.IsTrue(result);
            Assert.AreEqual(100111, docreq.DocumentId);

            // has the cache been polluted?
            cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes();
            Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]);             // no
            //Assert.AreEqual("1001/1001-1/1001-1-1", cachedRoutes[100111]); // yes

            // what's the nice url now?
            Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111));             // good
            //Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
        }
Exemplo n.º 3
0
        public void Match_Document_By_Url_Hide_Top_Level(string urlString, int expectedId)
        {
            var routingContext = GetRoutingContext(urlString);
            var url            = routingContext.UmbracoContext.CleanedUmbracoUrl;  //very important to use the cleaned up umbraco url
            var docreq         = new PublishedContentRequest(url, routingContext);
            var lookup         = new LookupByNiceUrl(false);

            SettingsForTests.HideTopLevelNodeFromPath = true;

            var result = lookup.TrySetDocument(docreq);

            if (expectedId > 0)
            {
                Assert.IsTrue(result);
                Assert.AreEqual(expectedId, docreq.DocumentId);
            }
            else
            {
                Assert.IsFalse(result);
            }
        }
        public void Lookup_SingleDomain(string url, int expectedId)
        {
            SetDomains3();

            ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");

            var routingContext = GetRoutingContext(url);
            var uri            = routingContext.UmbracoContext.CleanedUmbracoUrl;  //very important to use the cleaned up umbraco url
            var docreq         = new PublishedContentRequest(uri, routingContext);

            // must lookup domain else lookup by url fails
            var builder = new PublishedContentRequestBuilder(docreq);

            builder.LookupDomain();

            var lookup = new LookupByNiceUrl();
            var result = lookup.TrySetDocument(docreq);

            Assert.IsTrue(result);
            Assert.AreEqual(expectedId, docreq.DocumentId);
        }