Radarr/src/NzbDrone.Core.Test/Framework/MigrationTest.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2014-12-02 20:08:37 +00:00
using System;
using FluentMigrator;
2019-10-14 20:21:00 +00:00
using Microsoft.Extensions.Logging;
2014-12-02 20:08:37 +00:00
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration.Framework;
2014-12-02 20:08:37 +00:00
namespace NzbDrone.Core.Test.Framework
{
[Category("DbMigrationTest")]
[Category("DbTest")]
2019-12-22 22:08:53 +00:00
public abstract class MigrationTest<TMigration> : DbTest
where TMigration : NzbDroneMigrationBase
2014-12-02 20:08:37 +00:00
{
protected long MigrationVersion
2014-12-02 20:08:37 +00:00
{
get
2014-12-02 20:08:37 +00:00
{
var attrib = (MigrationAttribute)Attribute.GetCustomAttribute(typeof(TMigration), typeof(MigrationAttribute));
return attrib.Version;
}
}
protected virtual IDirectDataMapper WithMigrationTestDb(Action<TMigration> beforeMigration = null)
{
var db = WithTestDb(new MigrationContext(MigrationType, MigrationVersion)
{
BeforeMigration = m =>
2014-12-02 20:08:37 +00:00
{
var migration = m as TMigration;
if (beforeMigration != null && migration is TMigration)
{
beforeMigration(migration);
}
2014-12-02 20:08:37 +00:00
}
});
return db.GetDirectDataMapper();
2014-12-02 20:08:37 +00:00
}
2019-10-14 20:21:00 +00:00
protected override void SetupLogging()
{
Mocker.SetConstant<ILoggerProvider>(Mocker.Resolve<MigrationLoggerProvider>());
}
2014-12-02 20:08:37 +00:00
[SetUp]
public override void SetupDb()
{
SetupContainer();
}
}
2019-10-14 20:21:00 +00:00
}