Example #1
0
        public override void Initialize()
        {
            base.Initialize();

            var url = "/test";

            var lookup  = new Umbraco.Web.Routing.ContentFinderByNiceUrl();
            var lookups = new Umbraco.Web.Routing.IContentFinder[] { lookup };

            var t = Template.MakeNew("test", new User(0));

            var umbracoContext = GetUmbracoContext(url, t.Id);
            var urlProvider    = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() });
            var routingContext = new RoutingContext(
                umbracoContext,
                lookups,
                new FakeLastChanceFinder(),
                urlProvider);

            //assign the routing context back to the umbraco context
            umbracoContext.RoutingContext = routingContext;

            ////assign the routing context back to the umbraco context
            //umbracoContext.RoutingContext = routingContext;
            Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
        }
        public override void Initialize()
        {
            base.Initialize();

            //generate new mock settings and assign so we can configure in individual tests
            _umbracoSettings = SettingsForTests.GenerateMockSettings();
            SettingsForTests.ConfigureSettings(_umbracoSettings);

            var url = "/test";

            var lookup  = new Umbraco.Web.Routing.ContentFinderByNiceUrl();
            var lookups = new Umbraco.Web.Routing.IContentFinder[] { lookup };

            var t = Template.MakeNew("test", new User(0));

            var umbracoContext = GetUmbracoContext(url, t.Id);
            var urlProvider    = new UrlProvider(umbracoContext, _umbracoSettings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider() });
            var routingContext = new RoutingContext(
                umbracoContext,
                lookups,
                new FakeLastChanceFinder(),
                urlProvider);

            //assign the routing context back to the umbraco context
            umbracoContext.RoutingContext = routingContext;

            ////assign the routing context back to the umbraco context
            //umbracoContext.RoutingContext = routingContext;
            Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
        }
		public override void Initialize()
		{
			base.Initialize();

			var url = "/test";
			
			var lookup = new Umbraco.Web.Routing.ContentFinderByNiceUrl();
			var lookups = new Umbraco.Web.Routing.IContentFinder[] { lookup };

			var t = Template.MakeNew("test", new User(0));

			var umbracoContext = GetUmbracoContext(url, t.Id);
            var urlProvider = new UrlProvider(umbracoContext, new IUrlProvider[] { new DefaultUrlProvider() });
			var routingContext = new RoutingContext(
				umbracoContext,
				lookups,
				new FakeLastChanceFinder(),
                urlProvider);

			//assign the routing context back to the umbraco context
			umbracoContext.RoutingContext = routingContext;

			////assign the routing context back to the umbraco context
			//umbracoContext.RoutingContext = routingContext;
			Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
		}
		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 ContentFinderByNiceUrl();
            SettingsForTests.HideTopLevelNodeFromPath = false;

			var result = lookup.TryFindContent(docreq);

			Assert.IsTrue(result);
			Assert.AreEqual(expectedId, docreq.PublishedContent.Id);
		}
		public void DoNotPolluteCache()
		{
            SettingsForTests.UseDirectoryUrls = true;
            SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains            
            var requestMock = Mock.Get(UmbracoSettings.RequestHandler);
            requestMock.Setup(x => x.UseDomainPrefixes).Returns(true);

			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.UrlProvider.GetUrl(100111, true));

			// check that the proper route has been cached
		    var cache = routingContext.UmbracoContext.ContentCache.InnerCache as PublishedContentCache;
            if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
		    var cachedRoutes = cache.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 pcr = new PublishedContentRequest(uri, routingContext);
			pcr.Engine.FindDomain();
			Assert.IsTrue(pcr.HasDomain);

			// check that it's been routed
			var lookup = new ContentFinderByNiceUrl();
			var result = lookup.TryFindContent(pcr);
			Assert.IsTrue(result);
			Assert.AreEqual(100111, pcr.PublishedContent.Id);

			// has the cache been polluted?
            cachedRoutes = cache.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.UrlProvider.GetUrl(100111)); // good
			//Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
		}
		[TestCase("https://domain3.com/", 1001, "en-US")] // because domain3 is explicitely set on http

		public void Lookup_NestedDomains(string url, int expectedId, string expectedCulture)
		{
			SetDomains4();

            SettingsForTests.HideTopLevelNodeFromPath = true;

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

			// must lookup domain else lookup by url fails
			pcr.Engine.FindDomain();
			Assert.AreEqual(expectedCulture, pcr.Culture.Name);

			var lookup = new ContentFinderByNiceUrl();
			var result = lookup.TryFindContent(pcr);
			Assert.IsTrue(result);
			Assert.AreEqual(expectedId, pcr.PublishedContent.Id);
		}
        [TestCase("/1003/1003-1/1003-1-1", "nl-NL", 100311)] // wildcard on 10031 applies
        #endregion
        public void DomainAndCultureWithWildcards(string inputUrl, string expectedCulture, int expectedNode)
        {
            SetDomains2();

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

            // lookup domain
            pcr.Engine.FindDomain();

            // find document
            SettingsForTests.HideTopLevelNodeFromPath = false;
            var finder = new ContentFinderByNiceUrl();
            var result = finder.TryFindContent(pcr);

            // apply wildcard domain
            pcr.Engine.HandleWildcardDomains();

            Assert.IsTrue(result);
            Assert.AreEqual(expectedCulture, pcr.Culture.Name);
            Assert.AreEqual(pcr.PublishedContent.Id, expectedNode);
        }