1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-29 23:01:46 +01:00
bitwarden-server/test/Infrastructure.EFIntegration.Test/Helpers/DatabaseOptionsFactory.cs
2022-08-29 16:06:55 -04:00

26 lines
1.1 KiB
C#

using Bit.Core.Test.Helpers.Factories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
namespace Bit.Infrastructure.EFIntegration.Test.Helpers;
public static class DatabaseOptionsFactory
{
public static List<DbContextOptions<DatabaseContext>> Options { get; } = new();
static DatabaseOptionsFactory()
{
var globalSettings = GlobalSettingsFactory.GlobalSettings;
if (!string.IsNullOrWhiteSpace(GlobalSettingsFactory.GlobalSettings.PostgreSql?.ConnectionString))
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
Options.Add(new DbContextOptionsBuilder<DatabaseContext>().UseNpgsql(globalSettings.PostgreSql.ConnectionString).Options);
}
if (!string.IsNullOrWhiteSpace(GlobalSettingsFactory.GlobalSettings.MySql?.ConnectionString))
{
var mySqlConnectionString = globalSettings.MySql.ConnectionString;
Options.Add(new DbContextOptionsBuilder<DatabaseContext>().UseMySql(mySqlConnectionString, ServerVersion.AutoDetect(mySqlConnectionString)).Options);
}
}
}