From 4d0b2b745ac3035364854400a5410d248c210beb Mon Sep 17 00:00:00 2001 From: Shannon Date: Sun, 20 Dec 2015 17:28:38 +0100 Subject: [PATCH] first unit tests passing --- src/Umbraco.Core/CoreBootManager.cs | 3 ++ src/Umbraco.Core/UmbracoApplicationBase.cs | 1 - .../BootManagers/CoreBootManagerTests.cs | 44 ++----------------- .../DefaultUmbracoContextAccessor.cs | 17 +++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + src/Umbraco.Web/WebBootManager.cs | 15 +++++-- 6 files changed, 36 insertions(+), 45 deletions(-) create mode 100644 src/Umbraco.Web/DefaultUmbracoContextAccessor.cs diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index fc569b83f3..c56b02d74e 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -176,6 +176,9 @@ namespace Umbraco.Core container.Register(factory => FileSystemProviderManager.Current.GetFileSystemProvider()); container.Register(factory => factory.GetInstance().SqlSyntax); + + //These will be replaced by the web boot manager when running in a web context + container.Register(); } /// diff --git a/src/Umbraco.Core/UmbracoApplicationBase.cs b/src/Umbraco.Core/UmbracoApplicationBase.cs index 04bae95290..d83410aad0 100644 --- a/src/Umbraco.Core/UmbracoApplicationBase.cs +++ b/src/Umbraco.Core/UmbracoApplicationBase.cs @@ -260,7 +260,6 @@ namespace Umbraco.Core /// Returns the logger instance for the application - this will be used throughout the entire app /// public virtual ILogger Logger - // LoggerResolver can resolve before resolution is frozen { get { return _logger ?? (_logger = Logging.Logger.CreateWithDefaultLog4NetConfiguration()); } } diff --git a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs index a6c326e0cd..12e5f8de6a 100644 --- a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs +++ b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs @@ -61,45 +61,6 @@ namespace Umbraco.Tests.BootManagers : base(umbracoApplication, logger) { } - - ///// - ///// Creates and returns the application context singleton - ///// - ///// - ///// - //protected override ApplicationContext CreateApplicationContext(DatabaseContext dbContext, ServiceContext serviceContext) - //{ - // var appContext = base.CreateApplicationContext(dbContext, serviceContext); - - // var dbContextMock = new Mock(Mock.Of(), ProfilingLogger.Logger, Mock.Of(), "test"); - // dbContextMock.Setup(x => x.CanConnect).Returns(true); - // appContext.DatabaseContext = dbContextMock.Object; - - // return appContext; - //} - - //protected override void InitializeApplicationEventsResolver() - //{ - // //create an empty resolver so we can add our own custom ones (don't type find) - // ApplicationEventsResolver.Current = new ApplicationEventsResolver( - // new ActivatorServiceProvider(), ProfilingLogger.Logger, - // new Type[] - // { - // typeof(LegacyStartupHandler), - // typeof(TestApplicationEventHandler) - // }) - // { - // CanResolveBeforeFrozen = true - // }; - //} - - //protected override void InitializeLoggerResolver() - //{ - //} - - //protected override void InitializeProfilerResolver() - //{ - //} } /// @@ -138,7 +99,7 @@ namespace Umbraco.Tests.BootManagers } [Test] - public void Ensure_Legacy_Startup_Handlers_Not_Started_Until_Complete() + public void Raises_Events() { using (var app = new TestApp()) { @@ -146,9 +107,12 @@ namespace Umbraco.Tests.BootManagers { Assert.IsTrue(TestApplicationEventHandler.Initialized); Assert.IsTrue(TestApplicationEventHandler.Starting); + Assert.IsFalse(TestApplicationEventHandler.Started); }; EventHandler started = (sender, args) => { + Assert.IsTrue(TestApplicationEventHandler.Initialized); + Assert.IsTrue(TestApplicationEventHandler.Starting); Assert.IsTrue(TestApplicationEventHandler.Started); }; diff --git a/src/Umbraco.Web/DefaultUmbracoContextAccessor.cs b/src/Umbraco.Web/DefaultUmbracoContextAccessor.cs new file mode 100644 index 0000000000..1e413429a1 --- /dev/null +++ b/src/Umbraco.Web/DefaultUmbracoContextAccessor.cs @@ -0,0 +1,17 @@ +namespace Umbraco.Web +{ + internal class DefaultUmbracoContextAccessor : IUmbracoContextAccessor + { + private readonly UmbracoContext _umbracoContext; + + public DefaultUmbracoContextAccessor(UmbracoContext umbracoContext) + { + _umbracoContext = umbracoContext; + } + + public UmbracoContext Value + { + get { return _umbracoContext; } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 8eb32ef53c..327d7b4c92 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -310,6 +310,7 @@ + diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 796b65c545..d1c5177652 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -42,6 +42,7 @@ using Umbraco.Web.Scheduling; using Umbraco.Web.UI.JavaScript; using Umbraco.Web.WebApi; using umbraco.BusinessLogic; +using Umbraco.Core.Events; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; @@ -154,6 +155,7 @@ namespace Umbraco.Web return new WebProfiler(); } + /// /// Ensure that the OnApplicationStarted methods of the IApplicationEvents are called /// /// @@ -257,7 +259,7 @@ namespace Umbraco.Web } //need to get the plugin controllers that are unique to each area (group by) - var pluginSurfaceControlleres = pluginControllers.Where(x => !PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace()); + var pluginSurfaceControlleres = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace() == false); var groupedAreas = pluginSurfaceControlleres.GroupBy(controller => PluginController.GetMetadata(controller).AreaName); //loop through each area defined amongst the controllers foreach (var g in groupedAreas) @@ -313,16 +315,21 @@ namespace Umbraco.Web { base.ConfigureServices(container); + //Replace services: + container.Register(); + //IoC setup for LightInject for mvc/webapi - MvcContainerExtensions.EnableMvc(Container); + Container.EnableMvc(); Container.RegisterMvcControllers(PluginManager); container.EnablePerWebRequestScope(); container.EnableWebApi(GlobalConfiguration.Configuration); container.RegisterApiControllers(PluginManager); //register other services - container.Register(); - container.Register(); + container.Register(new PerRequestLifeTime()); + //TODO: Is this lifespan correct? Need to ask Stephen because we have contextual ones too + container.Register(new PerContainerLifetime()); + container.Register(new PerContainerLifetime()); //no need to declare as per request, currently we manage it's lifetime as the singleton container.Register(factory => UmbracoContext.Current); }