* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
54 lines
2.3 KiB
C#
54 lines
2.3 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System;
|
|
using System.IO;
|
|
using Microsoft.Extensions.Logging;
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Testing
|
|
{
|
|
public class TestDatabaseFactory
|
|
{
|
|
public static ITestDatabase Create(TestDatabaseSettings settings, string filesPath, ILoggerFactory loggerFactory, TestUmbracoDatabaseFactoryProvider dbFactory)
|
|
{
|
|
string connectionString = Environment.GetEnvironmentVariable("UmbracoIntegrationTestConnectionString");
|
|
|
|
return string.IsNullOrEmpty(connectionString)
|
|
? CreateLocalDb(settings, filesPath, loggerFactory, dbFactory)
|
|
: CreateSqlDeveloper(settings, loggerFactory, dbFactory, connectionString);
|
|
}
|
|
|
|
private static ITestDatabase CreateLocalDb(TestDatabaseSettings settings, string filesPath, ILoggerFactory loggerFactory, TestUmbracoDatabaseFactoryProvider dbFactory)
|
|
{
|
|
if (!Directory.Exists(filesPath))
|
|
{
|
|
Directory.CreateDirectory(filesPath);
|
|
}
|
|
|
|
var localDb = new LocalDb();
|
|
|
|
if (!localDb.IsAvailable)
|
|
{
|
|
throw new InvalidOperationException("LocalDB is not available.");
|
|
}
|
|
|
|
return new LocalDbTestDatabase(settings, loggerFactory, localDb, filesPath, dbFactory.Create());
|
|
}
|
|
|
|
private static ITestDatabase CreateSqlDeveloper(TestDatabaseSettings settings, 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
|
|
if (string.IsNullOrEmpty(connectionString))
|
|
{
|
|
throw new InvalidOperationException("ENV: UmbracoIntegrationTestConnectionString is not set");
|
|
}
|
|
|
|
return new SqlDeveloperTestDatabase(settings, loggerFactory, dbFactory.Create(), connectionString);
|
|
}
|
|
}
|
|
}
|