From 80ee2356d59ab61a2b1f5cc12a65c27b6f32fb07 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 16 Sep 2020 08:57:06 +0200 Subject: [PATCH] Fix a bunch of tests and try to add ILoggerFactory to Current --- src/Umbraco.Core/Composing/Current.cs | 4 ++++ .../BatchedDatabaseServerMessenger.cs | 3 ++- .../Testing/IntegrationTestComposer.cs | 4 ++-- .../XmlPublishedSnapshotService.cs | 4 ++-- .../PublishedContent/NuCacheChildrenTests.cs | 4 ++++ src/Umbraco.Tests/PublishedContent/NuCacheTests.cs | 4 ++++ src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs | 10 ++++++---- src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs | 2 ++ .../Services/ContentTypeServiceVariantsTests.cs | 2 ++ src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs | 4 ++-- src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs | 2 +- src/Umbraco.Web/Composing/Current.cs | 4 ++++ src/Umbraco.Web/UmbracoApplication.cs | 7 ++++--- src/Umbraco.Web/UmbracoApplicationBase.cs | 5 ++++- 14 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 055a29228a..1ca99e1348 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -1,16 +1,19 @@ using System; using System.Runtime.CompilerServices; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Composing { public static class Current { private static ILogger _logger = new NullLogger(); + private static ILoggerFactory _loggerFactory; private static Configs _configs; private static IIOHelper _ioHelper; private static IHostingEnvironment _hostingEnvironment; @@ -23,6 +26,7 @@ namespace Umbraco.Composing public static IHostingEnvironment HostingEnvironment => EnsureInitialized(_hostingEnvironment); public static IBackOfficeInfo BackOfficeInfo => EnsureInitialized(_backOfficeInfo); public static IProfiler Profiler => EnsureInitialized(_profiler); + public static ILoggerFactory LoggerFactory => EnsureInitialized(_loggerFactory); public static bool IsInitialized { get; internal set; } diff --git a/src/Umbraco.Infrastructure/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Infrastructure/BatchedDatabaseServerMessenger.cs index b3c5b00472..7792a5dc67 100644 --- a/src/Umbraco.Infrastructure/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Infrastructure/BatchedDatabaseServerMessenger.cs @@ -32,13 +32,14 @@ namespace Umbraco.Web IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, + ILogger logger, IServerRegistrar serverRegistrar, DatabaseServerMessengerOptions options, IHostingEnvironment hostingEnvironment, CacheRefresherCollection cacheRefreshers, IRequestCache requestCache, IRequestAccessor requestAccessor) - : base(mainDom, scopeProvider, sqlContext, proflog, serverRegistrar, true, options, hostingEnvironment, cacheRefreshers) + : base(mainDom, scopeProvider, sqlContext, proflog, logger, serverRegistrar, true, options, hostingEnvironment, cacheRefreshers) { _databaseFactory = databaseFactory; _requestCache = requestCache; diff --git a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs index 76480da97e..7be6325b92 100644 --- a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs +++ b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs @@ -87,8 +87,8 @@ namespace Umbraco.Tests.Integration.Testing // replace the default so there is no background index rebuilder private class TestBackgroundIndexRebuilder : BackgroundIndexRebuilder { - public TestBackgroundIndexRebuilder(IMainDom mainDom, IProfilingLogger pLogger, IApplicationShutdownRegistry hostingEnvironment, IndexRebuilder indexRebuilder) - : base(mainDom, pLogger, hostingEnvironment, indexRebuilder) + public TestBackgroundIndexRebuilder(IMainDom mainDom, IProfilingLogger pLogger, ILogger logger, IApplicationShutdownRegistry hostingEnvironment, IndexRebuilder indexRebuilder) + : base(mainDom, pLogger, logger, hostingEnvironment, indexRebuilder) { } diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs index bf7cbe40c4..42ecd971f2 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs @@ -55,7 +55,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache IUmbracoContextAccessor umbracoContextAccessor, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, - ILogger logger, + Microsoft.Extensions.Logging.ILogger logger, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, @@ -83,7 +83,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache IUmbracoContextAccessor umbracoContextAccessor, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, - ILogger logger, + Microsoft.Extensions.Logging.ILogger logger, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index f0aa39fcf8..f9320b3e60 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -31,6 +32,7 @@ using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.NuCache; using Umbraco.Web.PublishedCache.NuCache.DataSource; using Current = Umbraco.Web.Composing.Current; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Tests.PublishedContent { @@ -158,6 +160,8 @@ namespace Umbraco.Tests.PublishedContent _snapshotAccessor, _variationAccesor, Mock.Of(), + Mock.Of>(), + Mock.Of(), scopeProvider.Object, Mock.Of(), Mock.Of(), diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 8003bdf236..07b9c36d4a 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -29,6 +30,7 @@ using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.NuCache; using Umbraco.Web.PublishedCache.NuCache.DataSource; using Current = Umbraco.Web.Composing.Current; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Tests.PublishedContent { @@ -198,6 +200,8 @@ namespace Umbraco.Tests.PublishedContent new TestPublishedSnapshotAccessor(), _variationAccesor, Mock.Of(), + Mock.Of>(), + Mock.Of(), scopeProvider, Mock.Of(), Mock.Of(), diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 25e7fbb456..b49421c708 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using Examine; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -24,6 +25,7 @@ using Umbraco.Web; using Umbraco.Web.Hosting; using Umbraco.Web.Runtime; using Current = Umbraco.Web.Composing.Current; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Tests.Runtimes { @@ -108,17 +110,17 @@ namespace Umbraco.Tests.Runtimes public IRuntime Runtime { get; private set; } - protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, ILoggerFactory loggerFactory, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { - return Runtime = new TestRuntime(configs, umbracoVersion, ioHelper, logger, profiler, hostingEnvironment, backOfficeInfo); + return Runtime = new TestRuntime(configs, umbracoVersion, ioHelper, logger, loggerFactory, profiler, hostingEnvironment, backOfficeInfo); } } // test runtime public class TestRuntime : CoreRuntime { - public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) - :base(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), AppCaches.NoCache) + public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, ILoggerFactory loggerFactory, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + :base(configs, umbracoVersion, ioHelper, logger, loggerFactory, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, TestHelper.DbProviderFactoryCreator, TestHelper.MainDom, TestHelper.GetTypeFinder(), AppCaches.NoCache) { } diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 49bca378c7..db3ec8c80b 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -98,6 +98,8 @@ namespace Umbraco.Tests.Scoping publishedSnapshotAccessor, Mock.Of(), ProfilingLogger, + Mock.Of>(), + Mock.Of(), ScopeProvider, documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index ab9f85aa3c..f8d0116772 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -70,6 +70,8 @@ namespace Umbraco.Tests.Services publishedSnapshotAccessor, Mock.Of(), ProfilingLogger, + Mock.Of>(), + Mock.Of(), ScopeProvider, documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 6616e94339..2212ede7cb 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -246,7 +246,7 @@ namespace Umbraco.Tests.TestHelpers Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), - Logger); + Factory.GetInstance()); // testing=true so XmlStore will not use the file nor the database @@ -260,7 +260,7 @@ namespace Umbraco.Tests.TestHelpers Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), Factory.GetInstance(), DefaultCultureAccessor, - Logger, + Factory.GetInstance(), Factory.GetInstance(), HostingEnvironment, HostingLifetime, diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index 6f1a073eca..711676f8c1 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -421,7 +421,7 @@ namespace Umbraco.Tests.Web.Mvc null, null, umbracoContextAccessor, null, null, null, new TestDefaultCultureAccessor(), - Current.Logger, TestObjects.GetGlobalSettings(), + Current.LoggerFactory.CreateLogger("XmlPublishedSnapshotService"), TestObjects.GetGlobalSettings(), TestHelper.GetHostingEnvironment(), TestHelper.GetHostingEnvironmentLifetime(), ShortStringHelper, diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index 68120947df..b41a45ae2d 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Dictionary; @@ -33,6 +34,7 @@ using Umbraco.Web.Security; using Umbraco.Web.Services; using Umbraco.Web.Trees; using Umbraco.Web.WebApi; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Web.Composing { @@ -247,6 +249,8 @@ namespace Umbraco.Web.Composing public static ILogger Logger => Umbraco.Composing.Current.Logger; + public static ILoggerFactory LoggerFactory => Umbraco.Composing.Current.LoggerFactory; + public static IProfiler Profiler => Factory.GetInstance(); public static IProfilerHtml ProfilerHtml => Factory.GetInstance(); diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 2e9ba11866..3af09eb3e6 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Web; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Runtime; using Umbraco.Core.Configuration; @@ -14,6 +14,7 @@ using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Web.Runtime; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Web { @@ -22,7 +23,7 @@ namespace Umbraco.Web /// public class UmbracoApplication : UmbracoApplicationBase { - protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) + protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, ILoggerFactory loggerFactory, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo) { var connectionStringConfig = configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; @@ -49,7 +50,7 @@ namespace Umbraco.Web new IsolatedCaches(type => new DeepCloneAppCache(new ObjectCacheAppCache()))); var umbracoBootPermissionChecker = new AspNetUmbracoBootPermissionChecker(); - return new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, + return new CoreRuntime(configs, umbracoVersion, ioHelper, logger, loggerFactory, profiler, umbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom, GetTypeFinder(hostingEnvironment, logger, profiler), appCaches); } diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 86fc7de76c..8d40a36240 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Threading; using System.Web; using System.Web.Hosting; +using Microsoft.Extensions.Logging; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; @@ -19,6 +20,7 @@ using Umbraco.Web.AspNet; using Umbraco.Web.Hosting; using Umbraco.Web.Logging; using Current = Umbraco.Web.Composing.Current; +using ILogger = Umbraco.Core.Logging.ILogger; namespace Umbraco.Web { @@ -120,7 +122,7 @@ namespace Umbraco.Web /// /// Gets a runtime. /// - protected abstract IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo); + protected abstract IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, ILoggerFactory loggerFactory, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo); /// /// Gets the application register. @@ -170,6 +172,7 @@ namespace Umbraco.Web umbracoVersion, Umbraco.Composing.Current.IOHelper, Umbraco.Composing.Current.Logger, + Umbraco.Composing.Current.LoggerFactory, Umbraco.Composing.Current.Profiler, Umbraco.Composing.Current.HostingEnvironment, Umbraco.Composing.Current.BackOfficeInfo);