public void SetUp()
		{
			TestHelper.SetupLog4NetForTests();
			Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
			_httpContextFactory = new FakeHttpContextFactory("~/Home");
			//ensure the StateHelper is using our custom context
			StateHelper.HttpContext = _httpContextFactory.HttpContext;
			
			_umbracoContext = new UmbracoContext(_httpContextFactory.HttpContext, 
				new ApplicationContext(), 
				new DefaultRoutesCache(false));

			_umbracoContext.GetXmlDelegate = () =>
				{
					var xDoc = new XmlDocument();

					//create a custom xml structure to return

					xDoc.LoadXml(GetXml());
					//return the custom x doc
					return xDoc;
				};

			_publishedContentStore = new DefaultPublishedContentStore();			
		}
		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;
		}
		internal IPublishedContent GetNode(int id)
		{
			var ctx = GetUmbracoContext("/test", 1234);
			var contentStore = new DefaultPublishedContentStore();
			var doc = contentStore.GetDocumentById(ctx, id);
			Assert.IsNotNull(doc);
			return doc;
		}
Example #4
0
		/// <summary>
		/// Return a new RoutingContext
		/// </summary>
		/// <param name="url"></param>
		/// <param name="templateId">
		/// The template Id to insert into the Xml cache file for each node, this is helpful for unit testing with templates but you		 
		/// should normally create the template in the database with this id
		///</param>
		/// <param name="routeData"></param>
		/// <returns></returns>
		protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null)
		{
			var umbracoContext = GetUmbracoContext(url, templateId, routeData);
			var contentStore = new DefaultPublishedContentStore();
			var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
			var routingContext = new RoutingContext(
				umbracoContext,
				Enumerable.Empty<IPublishedContentLookup>(),
				new FakeLastChanceLookup(),
				contentStore,
				niceUrls);

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

			return routingContext;
		}