From 9ad813d990daf4328d98cdc2eea6be394c9ae656 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 15 Feb 2013 19:38:33 +0600 Subject: [PATCH] Fixes a couple issues with some routing tests. --- .../Routing/RenderRouteHandlerTests.cs | 3 ++- .../TestHelpers/BaseRoutingTest.cs | 26 +++++++++++-------- src/Umbraco.Web/Mvc/RenderMvcController.cs | 6 +++++ src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 8cdd512b7e..fa59741e8a 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -38,6 +38,7 @@ namespace Umbraco.Tests.Routing public override void TearDown() { base.TearDown(); + UmbracoContext.Current = null; RouteTable.Routes.Clear(); System.Configuration.ConfigurationManager.AppSettings.Set("umbracoPath", ""); SurfaceControllerResolver.Reset(); @@ -97,7 +98,7 @@ namespace Umbraco.Tests.Routing var template = CreateTemplate(templateName); var route = RouteTable.Routes["Umbraco_default"]; var routeData = new RouteData() {Route = route}; - var routingContext = GetRoutingContext("~/dummy-page", template.Id, routeData); + var routingContext = GetRoutingContext("~/dummy-page", template.Id, routeData, true); var docRequest = new PublishedContentRequest(routingContext.UmbracoContext.CleanedUmbracoUrl, routingContext) { PublishedContent = routingContext.PublishedContentStore.GetDocumentById(routingContext.UmbracoContext, 1172), diff --git a/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs b/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs index 515dee3fab..039ac23b50 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseRoutingTest.cs @@ -25,17 +25,18 @@ namespace Umbraco.Tests.TestHelpers ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", ""); } - /// - /// Return a new RoutingContext - /// - /// - /// - /// 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 - /// - /// - /// - protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null) + /// + /// Return a new RoutingContext + /// + /// + /// + /// 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 + /// + /// + /// set to true to also set the singleton UmbracoContext.Current to the context created with this method + /// + protected RoutingContext GetRoutingContext(string url, int templateId, RouteData routeData = null, bool setUmbracoContextCurrent = false) { var umbracoContext = GetUmbracoContext(url, templateId, routeData); var contentStore = new DefaultPublishedContentStore(); @@ -51,6 +52,9 @@ namespace Umbraco.Tests.TestHelpers //assign the routing context back to the umbraco context umbracoContext.RoutingContext = routingContext; + if (setUmbracoContextCurrent) + UmbracoContext.Current = umbracoContext; + return routingContext; } diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 9b8c5b505d..0f26610070 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -22,6 +22,12 @@ namespace Umbraco.Web.Mvc { ActionInvoker = new RenderActionInvoker(); } + + public RenderMvcController(UmbracoContext umbracoContext) + : base(umbracoContext) + { + + } private PublishedContentRequest _publishedContentRequest; diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 865a0e3d05..18f88ad54f 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -232,7 +232,7 @@ namespace Umbraco.Web.Mvc var def = new RouteDefinition { ControllerName = defaultControllerName, - Controller = new RenderMvcController(), + Controller = new RenderMvcController(UmbracoContext), PublishedContentRequest = publishedContentRequest, ActionName = ((Route)requestContext.RouteData.Route).Defaults["action"].ToString(), HasHijackedRoute = false