private void GiveControllerContext() { if (HasAnyController) { if (HasApiController) { if (ApiController.ControllerContext == null) { ApiController.ControllerContext = UmbracoUnitTestHelper.GetApiControllerContext(NeedsHttpRouteData()); } } else if (HasMvcController) { if (Controller.ControllerContext == null) { Controller.ControllerContext = UmbracoUnitTestHelper.GetControllerContext(UmbracoContext, Controller, NeedsPublishedContentRequest(), NeedsRouteData()); } } } }
public void HelperCurrentPageTest() { //Setup UmbracoContext with mocks. Sets UmbracoContext.Current var ctx = UmbracoUnitTestHelper.GetUmbracoContext(); var content = new TestPublishedContent() { Name = "test" }; var controller = new BasicTestSurfaceController(); //Setting the controller context will provide the route data, route def, publushed content request, and current page to the surface controller controller.ControllerContext = UmbracoUnitTestHelper.GetControllerContext(ctx, controller, UmbracoUnitTestHelper.GetPublishedContentRequest(ctx, currentContent: content)); var res = controller.BasicCurrentPageAction(); var model = res.Model as string; Assert.AreEqual(content.Name, model); }