1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-04 14:13:28 +01:00
bitwarden-server/test/Infrastructure.IntegrationTest/DatabaseTheoryAttribute.cs

33 lines
874 B
C#
Raw Permalink Normal View History

using Microsoft.Extensions.Configuration;
using Xunit;
namespace Bit.Infrastructure.IntegrationTest;
public class DatabaseTheoryAttribute : TheoryAttribute
{
private static IConfiguration? _cachedConfiguration;
public DatabaseTheoryAttribute()
{
if (!HasAnyDatabaseSetup())
{
Skip = "No databases setup.";
}
}
private static bool HasAnyDatabaseSetup()
{
var config = GetConfiguration();
return config.GetDatabases().Length > 0;
}
public static IConfiguration GetConfiguration()
{
return _cachedConfiguration ??= new ConfigurationBuilder()
.AddUserSecrets<DatabaseDataAttribute>(optional: true, reloadOnChange: false)
.AddEnvironmentVariables("BW_TEST_")
.AddCommandLine(Environment.GetCommandLineArgs())
.Build();
}
}