public void Renders_View_When_No_Content_Published() { const string UmbracoPathSetting = "~/umbraco"; const string UmbracoPath = "/umbraco"; const string ViewPath = "~/config/splashes/NoNodes.cshtml"; var mockUmbracoContext = new Mock <IUmbracoContext>(); mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(false); var mockIOHelper = new Mock <IIOHelper>(); mockIOHelper.Setup(x => x.ResolveUrl(It.Is <string>(y => y == UmbracoPathSetting))).Returns(UmbracoPath); IOptions <GlobalSettings> globalSettings = Options.Create(new GlobalSettings() { UmbracoPath = UmbracoPathSetting, NoNodesViewPath = ViewPath, }); var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, globalSettings); var result = controller.Index() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(ViewPath, result.ViewName); var model = result.Model as NoNodesViewModel; Assert.IsNotNull(model); Assert.AreEqual(UmbracoPath, model.UmbracoPath); }
public void Renders_View_When_No_Content_Published() { const string umbracoPathSetting = "~/umbraco"; const string umbracoPath = "/umbraco"; const string viewPath = "~/config/splashes/NoNodes.cshtml"; var mockUmbracoContext = new Mock <IUmbracoContext>(); mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(false); var mockIOHelper = new Mock <IIOHelper>(); mockIOHelper.Setup(x => x.ResolveUrl(It.Is <string>(y => y == umbracoPathSetting))).Returns(umbracoPath); var mockHostingEnvironment = new Mock <IHostingEnvironment>(); mockHostingEnvironment.Setup(x => x.ToAbsolute(It.Is <string>(y => y == umbracoPathSetting))) .Returns(umbracoPath); var globalSettings = new TestOptionsSnapshot <GlobalSettings>(new GlobalSettings { UmbracoPath = umbracoPathSetting, NoNodesViewPath = viewPath, }); var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), globalSettings, mockHostingEnvironment.Object); var result = controller.Index() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(viewPath, result.ViewName); var model = result.Model as NoNodesViewModel; Assert.IsNotNull(model); Assert.AreEqual(umbracoPath, model.UmbracoPath); }
public void Redirects_To_Root_When_Content_Published() { var mockUmbracoContext = new Mock <IUmbracoContext>(); mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true); var mockIOHelper = new Mock <IIOHelper>(); var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, Options.Create(new GlobalSettings())); var result = controller.Index() as RedirectResult; Assert.IsNotNull(result); Assert.AreEqual("~/", result.Url); }