AB#5819 - Cleanup

This commit is contained in:
Bjarke Berg
2020-04-14 16:26:01 +02:00
parent d0135eae2b
commit ad4bce3b73
4 changed files with 8 additions and 14 deletions
@@ -333,11 +333,6 @@ namespace Umbraco.Core.Runtime
composition.RegisterUnique<HtmlImageSourceParser>();
composition.RegisterUnique<RichTextEditorPastedImages>();
// we should stop injecting UmbracoContext and always inject IUmbracoContextAccessor, however at the moment
// there are tons of places (controllers...) which require UmbracoContext in their ctor - so let's register
// a way to inject the UmbracoContext - DO NOT register this as Lifetime.Request since LI will dispose the context
// in it's own way but we don't want that to happen, we manage its lifetime ourselves.
composition.Register(factory => factory.GetInstance<IUmbracoContextAccessor>().UmbracoContext);
composition.RegisterUnique<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
composition.Register<IPublishedContentQuery>(factory =>
{
@@ -3,6 +3,7 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Tests.Common;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
@@ -15,11 +16,12 @@ namespace Umbraco.Tests.Web.Mvc
[Test]
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 mockGlobalSettings = new Mock<IGlobalSettings>();
var controller = new RenderNoContentController(mockUmbracoContext.Object, mockIOHelper.Object, mockGlobalSettings.Object);
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, mockGlobalSettings.Object);
var result = controller.Index() as RedirectResult;
@@ -40,7 +42,7 @@ namespace Umbraco.Tests.Web.Mvc
var mockGlobalSettings = new Mock<IGlobalSettings>();
mockGlobalSettings.SetupGet(x => x.UmbracoPath).Returns(UmbracoPathSetting);
mockGlobalSettings.SetupGet(x => x.NoNodesViewPath).Returns(ViewPath);
var controller = new RenderNoContentController(mockUmbracoContext.Object, mockIOHelper.Object, mockGlobalSettings.Object);
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, mockGlobalSettings.Object);
var result = controller.Index() as ViewResult;
Assert.IsNotNull(result);
@@ -42,9 +42,6 @@ namespace Umbraco.Web.Common.Runtime
composition.RegisterUnique<ICookieManager, AspNetCoreCookieManager>();
composition.RegisterMultipleUnique<ISessionIdResolver, ISessionManager, AspNetCoreSessionManager>();
composition.RegisterUnique<ISessionIdResolver, AspNetCoreSessionManager>();
}
}
}
@@ -8,20 +8,20 @@ namespace Umbraco.Web.Mvc
{
public class RenderNoContentController : Controller
{
private readonly IUmbracoContext _umbracoContext;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IIOHelper _ioHelper;
private readonly IGlobalSettings _globalSettings;
public RenderNoContentController(IUmbracoContext umbracoContext, IIOHelper ioHelper, IGlobalSettings globalSettings)
public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IGlobalSettings globalSettings)
{
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
}
public ActionResult Index()
{
var store = _umbracoContext.Content;
var store = _umbracoContextAccessor.UmbracoContext.Content;
if (store.HasContent())
{
// If there is actually content, go to the root.