2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-12-11 18:20:07 +00:00
|
|
|
using System;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
2021-01-18 15:40:22 +01:00
|
|
|
using Umbraco.Core.Migrations.Install;
|
2020-12-11 18:20:07 +00:00
|
|
|
using Umbraco.Core.Persistence;
|
|
|
|
|
using Umbraco.Core.Persistence.Mappers;
|
|
|
|
|
|
2021-02-11 08:30:27 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Testing
|
2020-12-11 18:20:07 +00:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// I want to be able to create a database for integration testsing without setting the connection string on the
|
|
|
|
|
/// singleton database factory forever.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TestUmbracoDatabaseFactoryProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly ILoggerFactory _loggerFactory;
|
|
|
|
|
private readonly IOptions<GlobalSettings> _globalSettings;
|
|
|
|
|
private readonly IOptions<ConnectionStrings> _connectionStrings;
|
|
|
|
|
private readonly Lazy<IMapperCollection> _mappers;
|
|
|
|
|
private readonly IDbProviderFactoryCreator _dbProviderFactoryCreator;
|
2021-01-18 15:40:22 +01:00
|
|
|
private readonly DatabaseSchemaCreatorFactory _databaseSchemaCreatorFactory;
|
2020-12-11 18:20:07 +00:00
|
|
|
|
|
|
|
|
public TestUmbracoDatabaseFactoryProvider(
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IOptions<GlobalSettings> globalSettings,
|
|
|
|
|
IOptions<ConnectionStrings> connectionStrings,
|
|
|
|
|
Lazy<IMapperCollection> mappers,
|
2021-01-18 15:40:22 +01:00
|
|
|
IDbProviderFactoryCreator dbProviderFactoryCreator,
|
|
|
|
|
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory)
|
2020-12-11 18:20:07 +00:00
|
|
|
{
|
|
|
|
|
_loggerFactory = loggerFactory;
|
|
|
|
|
_globalSettings = globalSettings;
|
|
|
|
|
_connectionStrings = connectionStrings;
|
|
|
|
|
_mappers = mappers;
|
|
|
|
|
_dbProviderFactoryCreator = dbProviderFactoryCreator;
|
2021-01-18 15:40:22 +01:00
|
|
|
_databaseSchemaCreatorFactory = databaseSchemaCreatorFactory;
|
2020-12-11 18:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IUmbracoDatabaseFactory Create()
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable once ArrangeMethodOrOperatorBody
|
|
|
|
|
return new UmbracoDatabaseFactory(
|
|
|
|
|
_loggerFactory.CreateLogger<UmbracoDatabaseFactory>(),
|
|
|
|
|
_loggerFactory,
|
|
|
|
|
_globalSettings.Value,
|
|
|
|
|
_connectionStrings.Value,
|
|
|
|
|
_mappers,
|
2021-01-18 15:40:22 +01:00
|
|
|
_dbProviderFactoryCreator,
|
|
|
|
|
_databaseSchemaCreatorFactory);
|
2020-12-11 18:20:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|