Fixup CoreRuntime so it starts after Startup.Configure

Makes integration tests play nice with Components as RuntimeLevel will be correct
This commit is contained in:
Paul Johnson
2020-12-16 01:54:49 +00:00
parent 91e2f58822
commit 431403e372
9 changed files with 82 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using Microsoft.Extensions.Logging;
using Umbraco.Core.Persistence;
@@ -8,13 +9,20 @@ namespace Umbraco.Tests.Integration.Testing
{
public static ITestDatabase Create(string filesPath, ILoggerFactory loggerFactory, TestUmbracoDatabaseFactoryProvider dbFactory)
{
return string.IsNullOrEmpty(Environment.GetEnvironmentVariable("UmbracoIntegrationTestConnectionString"))
? CreateLocalDb(filesPath, loggerFactory, dbFactory.Create())
: CreateSqlDeveloper(loggerFactory, dbFactory.Create());
var connectionString = Environment.GetEnvironmentVariable("UmbracoIntegrationTestConnectionString");
return string.IsNullOrEmpty(connectionString)
? CreateLocalDb(filesPath, loggerFactory, dbFactory)
: CreateSqlDeveloper(loggerFactory, dbFactory, connectionString);
}
private static ITestDatabase CreateLocalDb(string filesPath, ILoggerFactory loggerFactory, IUmbracoDatabaseFactory dbFactory)
private static ITestDatabase CreateLocalDb(string filesPath, ILoggerFactory loggerFactory, TestUmbracoDatabaseFactoryProvider dbFactory)
{
if (!Directory.Exists(filesPath))
{
Directory.CreateDirectory(filesPath);
}
var localDb = new LocalDb();
if (!localDb.IsAvailable)
@@ -22,22 +30,21 @@ namespace Umbraco.Tests.Integration.Testing
throw new InvalidOperationException("LocalDB is not available.");
}
return new LocalDbTestDatabase(loggerFactory, localDb, filesPath, dbFactory);
return new LocalDbTestDatabase(loggerFactory, localDb, filesPath, dbFactory.Create());
}
private static ITestDatabase CreateSqlDeveloper(ILoggerFactory loggerFactory, IUmbracoDatabaseFactory dbFactory)
private static ITestDatabase CreateSqlDeveloper(ILoggerFactory loggerFactory, TestUmbracoDatabaseFactoryProvider dbFactory, string connectionString)
{
// NOTE: Example setup for Linux box.
// $ export SA_PASSWORD=Foobar123!
// $ export UmbracoIntegrationTestConnectionString="Server=localhost,1433;User Id=sa;Password=$SA_PASSWORD;"
// $ docker run -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=$SA_PASSWORD" -e 'MSSQL_PID=Developer' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
var connectionString = Environment.GetEnvironmentVariable("UmbracoIntegrationTestConnectionString");
if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("ENV: UmbracoIntegrationTestConnectionString is not set");
}
return new SqlDeveloperTestDatabase(loggerFactory, dbFactory, connectionString);
return new SqlDeveloperTestDatabase(loggerFactory, dbFactory.Create(), connectionString);
}
}
}