fixing tests and merges

This commit is contained in:
Shannon
2020-03-23 16:39:27 +11:00
parent 1658fced23
commit 299e9eb209
5 changed files with 27 additions and 34 deletions
@@ -14,7 +14,7 @@ namespace Umbraco.Configuration
public AspNetCoreConfigsFactory(IConfiguration configuration)
{
_configuration = configuration;
_configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration));
}
public Configs Create()
+13 -5
View File
@@ -28,15 +28,15 @@ namespace Umbraco.Tests.Common
public abstract class TestHelperBase
{
private readonly ITypeFinder _typeFinder;
private readonly IConfigsFactory _configsFactory;
private IConfigsFactory _configsFactory;
private UriUtility _uriUtility;
private IIOHelper _ioHelper;
private Configs _configs;
private IUmbracoVersion _umbracoVersion;
public TestHelperBase(Assembly entryAssembly)
{
_configsFactory = new ConfigsFactory();
SettingsForTests = new SettingsForTests();
SettingsForTests = new SettingsForTests();
MainDom = new SimpleMainDom();
_typeFinder = new TypeFinder(Mock.Of<ILogger>(), new DefaultUmbracoAssemblyProvider(entryAssembly));
}
@@ -54,6 +54,7 @@ namespace Umbraco.Tests.Common
_configs = GetConfigsFactory().Create();
return _configs;
}
public IRuntimeState GetRuntimeState()
{
return new RuntimeState(
@@ -69,7 +70,12 @@ namespace Umbraco.Tests.Common
public abstract IBackOfficeInfo GetBackOfficeInfo();
public IConfigsFactory GetConfigsFactory() => _configsFactory;
public IConfigsFactory GetConfigsFactory()
{
if (_configsFactory == null)
_configsFactory = new ConfigsFactory();
return _configsFactory;
}
/// <summary>
/// Gets the current assembly directory.
@@ -133,7 +139,9 @@ namespace Umbraco.Tests.Common
public IUmbracoVersion GetUmbracoVersion()
{
return new UmbracoVersion(GetConfigs().Global());
if (_umbracoVersion == null)
_umbracoVersion = new UmbracoVersion(GetConfigs().Global());
return _umbracoVersion;
}
public IRegister GetRegister()
@@ -2,7 +2,9 @@
using LightInject.Microsoft.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Moq;
using NUnit.Framework;
@@ -66,7 +68,13 @@ namespace Umbraco.Tests.Integration
var serviceProviderFactory = new UmbracoServiceProviderFactory(container);
var umbracoContainer = serviceProviderFactory.GetContainer();
// Some IConfiguration must exist in the container first
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddEnvironmentVariables();
services.AddSingleton<IConfiguration>(x => configurationBuilder.Build());
// Add it!
services.AddUmbracoConfiguration();
services.AddUmbracoCore(umbracoContainer, GetType().Assembly);
// assert results
@@ -33,7 +33,6 @@ namespace Umbraco.Tests.TestHelpers
protected override void Compose()
{
base.Compose();
base.Compose();
Composition.RegisterUnique<IPublishedValueFallback, PublishedValueFallback>();
Composition.RegisterUnique<IProfilingLogger, ProfilingLogger>();
@@ -30,6 +30,9 @@ namespace Umbraco.Web.BackOffice.AspNetCore
{
var serviceProvider = services.BuildServiceProvider();
var configuration = serviceProvider.GetService<IConfiguration>();
if (configuration == null)
throw new InvalidOperationException($"Could not resolve {typeof(IConfiguration)} from the container");
var configsFactory = new AspNetCoreConfigsFactory(configuration);
var configs = configsFactory.Create();
@@ -112,33 +115,6 @@ namespace Umbraco.Web.BackOffice.AspNetCore
return coreRuntime;
}
public static IServiceCollection CreateCompositionRoot(
this IServiceCollection services,
IHttpContextAccessor httpContextAccessor,
IWebHostEnvironment webHostEnvironment,
IHostApplicationLifetime hostApplicationLifetime,
Configs configs)
{
var hostingSettings = configs.Hosting();
var coreDebug = configs.CoreDebug();
var globalSettings = configs.Global();
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment,
httpContextAccessor, hostApplicationLifetime);
var ioHelper = new IOHelper(hostingEnvironment, globalSettings);
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment,
new AspNetCoreSessionIdResolver(httpContextAccessor),
() => services.BuildServiceProvider().GetService<IRequestCache>(), coreDebug, ioHelper,
new AspNetCoreMarchal());
var backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);
var profiler = new LogProfiler(logger);
Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler);
return services;
}
private static void CreateCompositionRoot(IServiceCollection services)
{
// TODO: This isn't the best to have to resolve the services now but to avoid this will
@@ -150,6 +126,8 @@ namespace Umbraco.Web.BackOffice.AspNetCore
var hostApplicationLifetime = serviceProvider.GetRequiredService<IHostApplicationLifetime>();
var configs = serviceProvider.GetService<Configs>();
if (configs == null)
throw new InvalidOperationException($"Could not resolve type {typeof(Configs)} from the container, ensure {nameof(AddUmbracoConfiguration)} is called before calling {nameof(AddUmbracoCore)}");
var hostingSettings = configs.Hosting();
var coreDebug = configs.CoreDebug();