The core infrastructure backend (API, database, Docker, etc).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
1.0 KiB

using Bit.Core.Enums;
using Bit.Infrastructure.IntegrationTest.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.IntegrationTest.Utilities;
public class AutoMigrateAttribute : TestCustomizerAttribute
{
public AutoMigrateAttribute(string? migrationName = null)
{
MigrationName = migrationName;
}
public string? MigrationName { get; }
public override Task CustomizeAsync(CustomizationContext customizationContext)
{
// Add migration services
var database = customizationContext.Database;
if (database.Type == SupportedDatabaseProviders.SqlServer && !database.UseEf)
{
// Add migrator service
}
else
{
// Add migrator service
}
// Build services provider early and run migrations
var sp = customizationContext.Services.BuildServiceProvider();
var migrator = sp.GetRequiredService<IMigrationTesterService>();
migrator.ApplyMigration();
return Task.CompletedTask;
}
}