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 Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
2021-02-12 12:40:08 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Mappers;
|
2020-12-11 18:20:07 +00:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Testing;
|
2020-12-11 18:20:07 +00:00
|
|
|
|
2022-06-21 08:09:38 +02: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 IOptionsMonitor<ConnectionStrings> _connectionStrings;
|
|
|
|
|
private readonly DatabaseSchemaCreatorFactory _databaseSchemaCreatorFactory;
|
|
|
|
|
private readonly IDbProviderFactoryCreator _dbProviderFactoryCreator;
|
|
|
|
|
private readonly IOptions<GlobalSettings> _globalSettings;
|
|
|
|
|
private readonly ILoggerFactory _loggerFactory;
|
|
|
|
|
private readonly IMapperCollection _mappers;
|
|
|
|
|
private readonly NPocoMapperCollection _npocoMappers;
|
2020-12-11 18:20:07 +00:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public TestUmbracoDatabaseFactoryProvider(
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IOptions<GlobalSettings> globalSettings,
|
|
|
|
|
IOptionsMonitor<ConnectionStrings> connectionStrings,
|
|
|
|
|
IMapperCollection mappers,
|
|
|
|
|
IDbProviderFactoryCreator dbProviderFactoryCreator,
|
|
|
|
|
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory,
|
|
|
|
|
NPocoMapperCollection npocoMappers)
|
|
|
|
|
{
|
|
|
|
|
_loggerFactory = loggerFactory;
|
|
|
|
|
_globalSettings = globalSettings;
|
|
|
|
|
_connectionStrings = connectionStrings;
|
|
|
|
|
_mappers = mappers;
|
|
|
|
|
_dbProviderFactoryCreator = dbProviderFactoryCreator;
|
|
|
|
|
_databaseSchemaCreatorFactory = databaseSchemaCreatorFactory;
|
|
|
|
|
_npocoMappers = npocoMappers;
|
2020-12-11 18:20:07 +00:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
|
|
|
|
|
public IUmbracoDatabaseFactory Create()
|
|
|
|
|
=> new UmbracoDatabaseFactory(
|
|
|
|
|
_loggerFactory.CreateLogger<UmbracoDatabaseFactory>(),
|
|
|
|
|
_loggerFactory,
|
|
|
|
|
_globalSettings,
|
|
|
|
|
_connectionStrings,
|
|
|
|
|
_mappers,
|
|
|
|
|
_dbProviderFactoryCreator,
|
|
|
|
|
_databaseSchemaCreatorFactory,
|
|
|
|
|
_npocoMappers);
|
2020-12-11 18:20:07 +00:00
|
|
|
}
|