public override void Initialize()
		{
			base.Initialize();

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

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

			var umbracoContext = GetUmbracoContext(url, t.Id);
			var contentStore = new DefaultPublishedContentStore();
			var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
			var routingContext = new RoutingContext(
				umbracoContext,
				lookups,
				new FakeLastChanceLookup(),
				contentStore,
				niceUrls);

			//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;
		}
Ejemplo n.º 2
0
        public override void Initialize()
        {
            base.Initialize();

            var url = "/test";

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

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

            var umbracoContext = GetUmbracoContext(url, t.Id);
            var contentStore   = new DefaultPublishedContentStore();
            var niceUrls       = new NiceUrlProvider(contentStore, umbracoContext);
            var routingContext = new RoutingContext(
                umbracoContext,
                lookups,
                new FakeLastChanceLookup(),
                contentStore,
                niceUrls);

            //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;
        }
Ejemplo n.º 3
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);
		}
Ejemplo n.º 4
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
		}
Ejemplo n.º 5
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();
			ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");

			var result = lookup.TrySetDocument(docreq);

			if (expectedId > 0)
			{
				Assert.IsTrue(result);
				Assert.AreEqual(expectedId, docreq.DocumentId);
			}
			else
			{
				Assert.IsFalse(result);
			}
		}
		[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 docreq = new PublishedContentRequest(uri, routingContext);

			// must lookup domain else lookup by url fails
			var builder = new PublishedContentRequestBuilder(docreq);
			builder.LookupDomain();
			Assert.AreEqual(expectedCulture, docreq.Culture.Name);

			var lookup = new LookupByNiceUrl();
			var result = lookup.TrySetDocument(docreq);
			Assert.IsTrue(result);
			Assert.AreEqual(expectedId, docreq.DocumentId);
		}
		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);
		}