diff --git a/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs b/src/Umbraco.Core/Logging/ConsoleLogger.cs similarity index 98% rename from src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs rename to src/Umbraco.Core/Logging/ConsoleLogger.cs index 53d6078e4b..275b8d988b 100644 --- a/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs +++ b/src/Umbraco.Core/Logging/ConsoleLogger.cs @@ -1,7 +1,6 @@ using System; -using Umbraco.Core.Logging; -namespace Umbraco.Tests.TestHelpers +namespace Umbraco.Core.Logging { public class ConsoleLogger : ILogger { diff --git a/src/Umbraco.Core/Logging/ILogger.cs b/src/Umbraco.Core/Logging/ILogger.cs index 4f49d0b3b4..fe7d798ebf 100644 --- a/src/Umbraco.Core/Logging/ILogger.cs +++ b/src/Umbraco.Core/Logging/ILogger.cs @@ -2,6 +2,7 @@ namespace Umbraco.Core.Logging { + /// /// Defines the logging service. /// diff --git a/src/Umbraco.Infrastructure/Composing/LightInject/LightInjectContainer.cs b/src/Umbraco.Infrastructure/Composing/LightInject/LightInjectContainer.cs index 9cd54fe7b8..ecc74ec61f 100644 --- a/src/Umbraco.Infrastructure/Composing/LightInject/LightInjectContainer.cs +++ b/src/Umbraco.Infrastructure/Composing/LightInject/LightInjectContainer.cs @@ -21,6 +21,8 @@ namespace Umbraco.Core.Composing.LightInject Container = ConfigureContainer(container); } + //TODO: The Create methods can die when net framework is gone + /// /// Creates a new instance of the class. /// diff --git a/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs b/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs index 4a73795f68..1bf3b8187f 100644 --- a/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs +++ b/src/Umbraco.Infrastructure/Composing/RegisterFactory.cs @@ -1,5 +1,9 @@ -using System; +using LightInject; +using LightInject.Microsoft.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using System; using System.Reflection; +using Umbraco.Core.Composing.LightInject; using Umbraco.Core.Configuration; namespace Umbraco.Core.Composing @@ -9,7 +13,19 @@ namespace Umbraco.Core.Composing /// public static class RegisterFactory { - //TODO This needs to die + /// + /// Creates a new based on an existing MSDI IServiceCollection + /// + /// + /// + public static IRegister CreateFrom(IServiceCollection services, out IServiceProvider serviceProvider) + { + var liContainer = new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings()); + serviceProvider = liContainer.CreateServiceProvider(services); + return new LightInjectContainer(liContainer); + } + + //TODO: The following can die when net framework is gone // cannot use typeof().AssemblyQualifiedName on the web container - we don't reference it // a normal Umbraco site should run on the web container, but an app may run on the core one diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index 1db36a9c09..797c8bb7fa 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -7,10 +7,12 @@ - + + + @@ -65,4 +67,8 @@ + + + + diff --git a/src/Umbraco.Tests.Integration/CrossWireContainer.cs b/src/Umbraco.Tests.Integration/ContainerTests.cs similarity index 57% rename from src/Umbraco.Tests.Integration/CrossWireContainer.cs rename to src/Umbraco.Tests.Integration/ContainerTests.cs index 1bf5d4fb1c..1157e74bbf 100644 --- a/src/Umbraco.Tests.Integration/CrossWireContainer.cs +++ b/src/Umbraco.Tests.Integration/ContainerTests.cs @@ -13,11 +13,44 @@ using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; +using Umbraco.Core.Runtime; +using Umbraco.Tests.Integration.Infrastructure; namespace Umbraco.Tests.Integration { [TestFixture] - public class CrossWireContainer + public class RuntimeTests + { + [Test] + public void CoreRuntime() + { + // MSDI + var services = new ServiceCollection(); + var msdiServiceProvider = services.BuildServiceProvider(); + + // LightInject / Umbraco + var umbracoContainer = RegisterFactory.CreateFrom(services, out var lightInjectServiceProvider); + + // Dependencies needed for Core Runtime + var profiler = new VoidProfiler(); + var logger = new ProfilingLogger(new ConsoleLogger(new MessageTemplates()), profiler); + var hostingEnvironment = new TestHostingEnvironment(); + var ioHelper = new IOHelper(hostingEnvironment); + var configs = new Configs(x => null); + var umbracoVersion = new UmbracoVersion(); + var testUmbracoBootPermissionChecker = new TestUmbracoBootPermissionChecker(); + var globalSettings = new TestGlobalSettings(); + var backOfficeInfo = new TestBackOfficeInfo(globalSettings); + var dbFactoryProviderCreator = new TestDbProviderFactoryCreator(); + var mainDom = new SimpleMainDom(); + var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, testUmbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbFactoryProviderCreator, mainDom); + + var factory = coreRuntime.Boot(umbracoContainer); + } + } + + [TestFixture] + public class ContainerTests { [Test] public void CrossWire() @@ -27,26 +60,24 @@ namespace Umbraco.Tests.Integration services.AddSingleton(); var msdiServiceProvider = services.BuildServiceProvider(); - // LightInject - var liContainer = new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings()); - var liServiceProvider = liContainer.CreateServiceProvider(services); - - // Umbraco - var umbracoContainer = new LightInjectContainer(liContainer); + // LightInject / Umbraco + var umbracoContainer = (LightInjectContainer)RegisterFactory.CreateFrom(services, out var lightInjectServiceProvider); // Dependencies needed for creating composition/register essentials var tempPath = Path.Combine(Path.GetTempPath(), "umbraco-temp-" + Guid.NewGuid()); if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath); var globalSettings = Mock.Of(); - var typeFinder = Mock.Of(); - var ioHelper = Mock.Of(); + + var hostingEnvironment = new TestHostingEnvironment(); + var ioHelper = new IOHelper(hostingEnvironment); var runtimeCache = NoAppCache.Instance; - var logger = Mock.Of(); + var profiler = new VoidProfiler(); + var logger = new ProfilingLogger(new ConsoleLogger(new MessageTemplates()), profiler); + var typeFinder = new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly)); var typeLoader = new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(tempPath), logger, false); var runtimeState = Mock.Of(); var configs = new Configs(x => null); var appCaches = new AppCaches(runtimeCache, NoAppCache.Instance, new IsolatedCaches(type => new ObjectCacheAppCache(typeFinder))); - var profiler = new VoidProfiler(); var mainDom = Mock.Of(); var umbracoDatabaseFactory = Mock.Of(); var umbracoVersion = new UmbracoVersion(); @@ -60,7 +91,7 @@ namespace Umbraco.Tests.Integration // From MSDI var foo1 = msdiServiceProvider.GetService(); - var foo2 = liServiceProvider.GetService(); + var foo2 = lightInjectServiceProvider.GetService(); var foo3 = umbracoContainer.GetInstance(); Assert.IsNotNull(foo1); diff --git a/src/Umbraco.Tests.Integration/Infrastructure/TestBackOfficeInfo.cs b/src/Umbraco.Tests.Integration/Infrastructure/TestBackOfficeInfo.cs new file mode 100644 index 0000000000..a32dc5ac13 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Infrastructure/TestBackOfficeInfo.cs @@ -0,0 +1,17 @@ +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Tests.Integration.Infrastructure +{ + + public class TestBackOfficeInfo : IBackOfficeInfo + { + public TestBackOfficeInfo(IGlobalSettings globalSettings) + { + GetAbsoluteUrl = globalSettings.UmbracoPath; + } + + public string GetAbsoluteUrl { get; } + + } +} diff --git a/src/Umbraco.Tests.Integration/Infrastructure/TestDbProviderFactoryCreator.cs b/src/Umbraco.Tests.Integration/Infrastructure/TestDbProviderFactoryCreator.cs new file mode 100644 index 0000000000..f21c86c50e --- /dev/null +++ b/src/Umbraco.Tests.Integration/Infrastructure/TestDbProviderFactoryCreator.cs @@ -0,0 +1,34 @@ +using System.Data.Common; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.SqlSyntax; + +namespace Umbraco.Tests.Integration.Infrastructure +{ + public class TestDbProviderFactoryCreator : IDbProviderFactoryCreator + { + public IBulkSqlInsertProvider CreateBulkSqlInsertProvider(string providerName) + { + throw new System.NotImplementedException(); + } + + public void CreateDatabase() + { + throw new System.NotImplementedException(); + } + + public DbProviderFactory CreateFactory() + { + throw new System.NotImplementedException(); + } + + public DbProviderFactory CreateFactory(string providerName) + { + throw new System.NotImplementedException(); + } + + public ISqlSyntaxProvider GetSqlSyntaxProvider(string providerName) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/src/Umbraco.Tests.Integration/Infrastructure/TestGlobalSettings.cs b/src/Umbraco.Tests.Integration/Infrastructure/TestGlobalSettings.cs new file mode 100644 index 0000000000..2123de8c14 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Infrastructure/TestGlobalSettings.cs @@ -0,0 +1,49 @@ +using Umbraco.Core.Configuration; + +namespace Umbraco.Tests.Integration.Infrastructure +{ + public class TestGlobalSettings : IGlobalSettings + { + public string ReservedUrls => throw new System.NotImplementedException(); + + public string ReservedPaths => throw new System.NotImplementedException(); + + public string Path => throw new System.NotImplementedException(); + + public string ConfigurationStatus { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } + + public int TimeOutInMinutes => throw new System.NotImplementedException(); + + public string DefaultUILanguage => throw new System.NotImplementedException(); + + public bool HideTopLevelNodeFromPath => throw new System.NotImplementedException(); + + public bool UseHttps => throw new System.NotImplementedException(); + + public int VersionCheckPeriod => throw new System.NotImplementedException(); + + public string UmbracoPath => "/Umbraco"; + + public string UmbracoCssPath => throw new System.NotImplementedException(); + + public string UmbracoScriptsPath => throw new System.NotImplementedException(); + + public string UmbracoMediaPath => throw new System.NotImplementedException(); + + public bool IsSmtpServerConfigured => throw new System.NotImplementedException(); + + public ISmtpSettings SmtpSettings => throw new System.NotImplementedException(); + + public bool InstallMissingDatabase => throw new System.NotImplementedException(); + + public bool InstallEmptyDatabase => throw new System.NotImplementedException(); + + public bool DisableElectionForSingleServer => throw new System.NotImplementedException(); + + public string RegisterType => throw new System.NotImplementedException(); + + public string DatabaseFactoryServerVersion => throw new System.NotImplementedException(); + + public string MainDomLock => throw new System.NotImplementedException(); + } +} diff --git a/src/Umbraco.Tests.Integration/Infrastructure/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Infrastructure/TestHostingEnvironment.cs new file mode 100644 index 0000000000..4a05bb93c7 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Infrastructure/TestHostingEnvironment.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Umbraco.Core; +using Umbraco.Core.Hosting; + +namespace Umbraco.Tests.Integration.Infrastructure +{ + + public class TestHostingEnvironment : IHostingEnvironment + { + public TestHostingEnvironment() + { + var tempPath = Path.Combine(Path.GetTempPath(), "umbraco-temp-" + Guid.NewGuid()); + if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath); + LocalTempPath = tempPath; + ApplicationPhysicalPath = tempPath; // same location for now + } + + public string SiteName => "UmbracoIntegrationTests"; + + public string ApplicationId { get; } = Guid.NewGuid().ToString(); + + public string ApplicationPhysicalPath { get; private set; } + + public string LocalTempPath { get; private set; } + + public string ApplicationVirtualPath => "/"; + + public bool IsDebugMode => true; + + public bool IsHosted => false; + + public Version IISVersion => new Version(0, 0); // TODO not necessary IIS + + public string MapPath(string path) => Path.Combine(ApplicationPhysicalPath, path); + + public string ToAbsolute(string virtualPath, string root) => virtualPath.TrimStart('~'); + + public void RegisterObject(IRegisteredObject registeredObject) + { + } + + public void UnregisterObject(IRegisteredObject registeredObject) + { + } + } +} diff --git a/src/Umbraco.Tests.Integration/Infrastructure/TestUmbracoBootPermissionChecker.cs b/src/Umbraco.Tests.Integration/Infrastructure/TestUmbracoBootPermissionChecker.cs new file mode 100644 index 0000000000..f97e4fe0e0 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Infrastructure/TestUmbracoBootPermissionChecker.cs @@ -0,0 +1,11 @@ +using Umbraco.Core.Runtime; + +namespace Umbraco.Tests.Integration.Infrastructure +{ + public class TestUmbracoBootPermissionChecker : IUmbracoBootPermissionChecker + { + public void ThrowIfNotPermissions() + { + } + } +} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 56d36981b3..1b4f05af67 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -84,7 +84,7 @@ 1.8.14 - + @@ -210,7 +210,6 @@ - diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs index 5cd2b590c8..719b7d1323 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -83,9 +83,10 @@ namespace Umbraco.Web.BackOffice.AspNetCore } } - + // TODO: This may need to take into account ~/ paths which means the ApplicationVirtualPath and is this the content root or web root? public string MapPath(string path) => Path.Combine(_webHostEnvironment.WebRootPath, path); + // TODO: Need to take into account 'root' here public string ToAbsolute(string virtualPath, string root) { if (Uri.TryCreate(virtualPath, UriKind.Absolute, out _)) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index e9a4e04e58..6f5764f36e 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -71,7 +71,7 @@ 2.7.0.100 - +