diff --git a/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs index 317ad418f1..566b90b157 100644 --- a/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs @@ -1,7 +1,9 @@ +using System; using System.CodeDom; using System.Linq; using System.Web; using System.Web.Mvc; +using System.Web.Routing; using System.Web.Security; using Moq; using NUnit.Framework; @@ -35,7 +37,7 @@ namespace Umbraco.Tests.Mvc var umbCtx = UmbracoContext.EnsureContext( new Mock().Object, appCtx, - new Mock(null, null).Object, + new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), true); @@ -74,7 +76,7 @@ namespace Umbraco.Tests.Mvc MockHelper.GetMockedServiceContext(), CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); - + var umbCtx = UmbracoContext.EnsureContext( new Mock().Object, appCtx, @@ -104,7 +106,7 @@ namespace Umbraco.Tests.Mvc var helper = new UmbracoHelper( umbCtx, Mock.Of(), - Mock.Of(query => query.TypedContent(It.IsAny()) == + Mock.Of(query => query.TypedContent(It.IsAny()) == //return mock of IPublishedContent for any call to GetById Mock.Of(content => content.Id == 2)), Mock.Of(), @@ -114,12 +116,54 @@ namespace Umbraco.Tests.Mvc Mock.Of(), Mock.Of(), new MembershipHelper(umbCtx, Mock.Of(), Mock.Of())); - + var ctrl = new TestSurfaceController(umbCtx, helper); var result = ctrl.GetContent(2) as PublishedContentResult; Assert.IsNotNull(result); - Assert.AreEqual(2, result.Content.Id); + Assert.AreEqual(2, result.Content.Id); + } + + [Test] + public void Mock_Current_Page() + { + var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper()); + + var webRoutingSettings = Mock.Of(section => section.UrlProviderMode == "AutoLegacy"); + + var umbCtx = UmbracoContext.EnsureContext( + new Mock().Object, + appCtx, + new Mock(null, null).Object, + Mock.Of(section => section.WebRouting == webRoutingSettings), + Enumerable.Empty(), + true); + + var content = Mock.Of(publishedContent => publishedContent.Id == 12345); + + var contextBase = umbCtx.HttpContext; + var pcr = new PublishedContentRequest(new Uri("http://localhost/test"), + umbCtx.RoutingContext, + webRoutingSettings, + s => Enumerable.Empty()) + { + PublishedContent = content + }; + + var routeDefinition = new RouteDefinition + { + PublishedContentRequest = pcr + }; + + var routeData = new RouteData(); + routeData.DataTokens.Add("umbraco-route-def", routeDefinition); + + var ctrl = new TestSurfaceController(umbCtx, new UmbracoHelper()); + ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl); + + var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult; + + Assert.AreEqual(12345, result.Content.Id); } public class TestSurfaceController : SurfaceController @@ -156,6 +200,13 @@ namespace Umbraco.Tests.Mvc return new PublishedContentResult(content); } + + public ActionResult GetContentFromCurrentPage() + { + var content = CurrentPage; + + return new PublishedContentResult(content); + } } public class PublishedContentResult : ActionResult