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

48 lines
1.4 KiB
C#
Raw Normal View History

2014-12-02 20:08:37 +00:00
using System;
using FluentMigrator;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Test.Common.AutoMoq;
2014-12-02 20:08:37 +00:00
namespace NzbDrone.Core.Test.Framework
{
[Category("DbMigrationTest")]
[Category("DbTest")]
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
}
[SetUp]
public override void SetupDb()
{
SetupContainer();
}
[Obsolete("Don't use Mocker/Repositories in MigrationTests, query the DB.", true)]
2016-12-09 06:54:15 +00:00
public new AutoMoqer Mocker => base.Mocker;
2014-12-02 20:08:37 +00:00
}
}