From 7af04b0a2fc0f5b21d7f19a4321dfe606e86e550 Mon Sep 17 00:00:00 2001 From: Lars-Erik Aabech Date: Tue, 19 Jun 2018 19:59:12 +0200 Subject: [PATCH] Tests pass again --- src/Umbraco.Core/Composing/IContainer.cs | 1 + .../Composing/LightInject/ContainerAdapter.cs | 5 +++++ .../Routing/RenderRouteHandlerTests.cs | 8 +++++++ .../Stubs/TestControllerFactory.cs | 3 ++- ...RenderIndexActionSelectorAttributeTests.cs | 7 ++++-- .../Web/Mvc/SurfaceControllerTests.cs | 22 ++++++++++++++----- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/Composing/IContainer.cs b/src/Umbraco.Core/Composing/IContainer.cs index 4e9d8df3c5..a1206c5816 100644 --- a/src/Umbraco.Core/Composing/IContainer.cs +++ b/src/Umbraco.Core/Composing/IContainer.cs @@ -10,6 +10,7 @@ namespace Umbraco.Core.Composing { T TryGetInstance(); T GetInstance(); + object GetInstance(Type parameterType); object ConcreteContainer { get; } void RegisterSingleton(Func factory); void Register(Func factory); diff --git a/src/Umbraco.Core/Composing/LightInject/ContainerAdapter.cs b/src/Umbraco.Core/Composing/LightInject/ContainerAdapter.cs index 62e07683a3..906b66bcb1 100644 --- a/src/Umbraco.Core/Composing/LightInject/ContainerAdapter.cs +++ b/src/Umbraco.Core/Composing/LightInject/ContainerAdapter.cs @@ -42,5 +42,10 @@ namespace Umbraco.Core.Composing.LightInject { return container.GetInstance(); } + + public object GetInstance(Type type) + { + return container.GetInstance(type); + } } } diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index c64c70e65a..7e32921363 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -6,6 +6,7 @@ using LightInject; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; @@ -17,7 +18,10 @@ using Umbraco.Web.Routing; using Umbraco.Web.WebApi; using Umbraco.Core.Strings; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.Testing; using Umbraco.Tests.Testing.Objects.Accessors; @@ -182,6 +186,10 @@ namespace Umbraco.Tests.Routing /// public class CustomDocumentController : RenderMvcController { + public CustomDocumentController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(globalSettings, umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger) + { + } + public ActionResult HomePage(ContentModel model) { return View(); diff --git a/src/Umbraco.Tests/TestHelpers/Stubs/TestControllerFactory.cs b/src/Umbraco.Tests/TestHelpers/Stubs/TestControllerFactory.cs index 5e2ce24863..23dc0d4347 100644 --- a/src/Umbraco.Tests/TestHelpers/Stubs/TestControllerFactory.cs +++ b/src/Umbraco.Tests/TestHelpers/Stubs/TestControllerFactory.cs @@ -47,7 +47,8 @@ namespace Umbraco.Tests.TestHelpers.Stubs var allParams = ctor.GetParameters().ToArray(); foreach (var parameter in allParams) { - var found = possibleParams.SingleOrDefault(x => x.GetType() == parameter.ParameterType); + var found = possibleParams.SingleOrDefault(x => x.GetType() == parameter.ParameterType) + ?? Current.Container.GetInstance(parameter.ParameterType); if (found != null) args.Add(found); } if (args.Count == allParams.Length) diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index f4c15f7c19..bf29f7e35e 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -9,6 +9,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Profiling; @@ -17,12 +18,12 @@ using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Tests.Testing.Objects.Accessors; using Umbraco.Web; -using Umbraco.Web.Composing; using Umbraco.Web.Models; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Tests.Web.Mvc { @@ -33,6 +34,7 @@ namespace Umbraco.Tests.Web.Mvc public void SetUp() { Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); + Core.Composing.Current.Container = Mock.Of(); } [TearDown] @@ -156,7 +158,8 @@ namespace Umbraco.Tests.Web.Mvc } public class MatchesDefaultIndexController : RenderMvcController - { } + { + } public class MatchesOverriddenIndexController : RenderMvcController { diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index 4186c56636..f9cff5af9b 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -7,6 +7,7 @@ using System.Web.Security; using Moq; using NUnit.Framework; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Dictionary; using Umbraco.Core.Models.PublishedContent; @@ -16,11 +17,11 @@ using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Tests.Testing; using Umbraco.Tests.Testing.Objects.Accessors; using Umbraco.Web; -using Umbraco.Web.Composing; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Tests.Web.Mvc { @@ -49,7 +50,7 @@ namespace Umbraco.Tests.Web.Mvc new TestVariationContextAccessor(), true); - var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext }; + var ctrl = new TestSurfaceController(umbracoContext); var result = ctrl.Index(); @@ -71,7 +72,7 @@ namespace Umbraco.Tests.Web.Mvc new TestVariationContextAccessor(), true); - var ctrl = new TestSurfaceController { UmbracoContext = umbCtx }; + var ctrl = new TestSurfaceController(umbCtx); Assert.IsNotNull(ctrl.UmbracoContext); } @@ -91,7 +92,7 @@ namespace Umbraco.Tests.Web.Mvc new TestVariationContextAccessor(), true); - var controller = new TestSurfaceController { UmbracoContext = umbracoContext }; + var controller = new TestSurfaceController(umbracoContext); Container.Register(_ => umbracoContext); Container.InjectProperties(controller); @@ -132,7 +133,7 @@ namespace Umbraco.Tests.Web.Mvc new ServiceContext(), CacheHelper.CreateDisabledCacheHelper()); - var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext, Umbraco = helper }; + var ctrl = new TestSurfaceController(umbracoContext, helper); var result = ctrl.GetContent(2) as PublishedContentResult; Assert.IsNotNull(result); @@ -171,7 +172,7 @@ namespace Umbraco.Tests.Web.Mvc var routeData = new RouteData(); routeData.DataTokens.Add(Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition); - var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext, Umbraco = new UmbracoHelper() }; + var ctrl = new TestSurfaceController(umbracoContext, new UmbracoHelper()); ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl); var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult; @@ -181,6 +182,15 @@ namespace Umbraco.Tests.Web.Mvc public class TestSurfaceController : SurfaceController { + public TestSurfaceController(UmbracoContext ctx, UmbracoHelper helper = null) + : base(ctx, null, new ServiceContext(), Mock.Of(), null, null) + { + if (helper != null) + { + Umbraco = helper; + } + } + public ActionResult Index() { return View();