2022-12-02 20:24:30 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Infrastructure.IntegrationTest;
|
|
|
|
|
|
|
|
|
|
public class DatabaseTheoryAttribute : TheoryAttribute
|
|
|
|
|
{
|
|
|
|
|
private static IConfiguration? _cachedConfiguration;
|
|
|
|
|
|
|
|
|
|
public DatabaseTheoryAttribute()
|
|
|
|
|
{
|
|
|
|
|
if (!HasAnyDatabaseSetup())
|
|
|
|
|
{
|
2023-05-30 19:25:55 +02:00
|
|
|
|
Skip = "No databases setup.";
|
2022-12-02 20:24:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool HasAnyDatabaseSetup()
|
|
|
|
|
{
|
|
|
|
|
var config = GetConfiguration();
|
2023-05-30 19:25:55 +02:00
|
|
|
|
return config.GetDatabases().Length > 0;
|
2022-12-02 20:24:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IConfiguration GetConfiguration()
|
|
|
|
|
{
|
|
|
|
|
return _cachedConfiguration ??= new ConfigurationBuilder()
|
|
|
|
|
.AddUserSecrets<DatabaseDataAttribute>(optional: true, reloadOnChange: false)
|
|
|
|
|
.AddEnvironmentVariables("BW_TEST_")
|
|
|
|
|
.AddCommandLine(Environment.GetCommandLineArgs())
|
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
}
|