mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-22 22:16:13 -04:00
1169741c54
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using FluentMigrator;
|
|
using Microsoft.Extensions.Logging;
|
|
using NLog.Extensions.Logging;
|
|
using NUnit.Framework;
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
|
|
namespace NzbDrone.Core.Test.Framework
|
|
{
|
|
[Category("DbMigrationTest")]
|
|
[Category("DbTest")]
|
|
public abstract class MigrationTest<TMigration> : DbTest
|
|
where TMigration : NzbDroneMigrationBase
|
|
{
|
|
protected long MigrationVersion => ((MigrationAttribute)Attribute.GetCustomAttribute(typeof(TMigration), typeof(MigrationAttribute))).Version;
|
|
|
|
[SetUp]
|
|
public override void SetupDb()
|
|
{
|
|
SetupContainer();
|
|
}
|
|
|
|
protected virtual IDirectDataMapper WithMigrationTestDb(Action<TMigration> beforeMigration = null)
|
|
{
|
|
return WithMigrationAction(beforeMigration).GetDirectDataMapper();
|
|
}
|
|
|
|
protected virtual IDbConnection WithDapperMigrationTestDb(Action<TMigration> beforeMigration = null)
|
|
{
|
|
return WithMigrationAction(beforeMigration).OpenConnection();
|
|
}
|
|
|
|
protected override void SetupLogging()
|
|
{
|
|
Mocker.SetConstant<ILoggerProvider>(Mocker.Resolve<NLogLoggerProvider>());
|
|
}
|
|
|
|
private ITestDatabase WithMigrationAction(Action<TMigration> beforeMigration = null)
|
|
{
|
|
return WithTestDb(new MigrationContext(MigrationType, MigrationVersion)
|
|
{
|
|
BeforeMigration = m =>
|
|
{
|
|
if (beforeMigration != null && m is TMigration migration)
|
|
{
|
|
beforeMigration(migration);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|