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.
48 lines
1.4 KiB
48 lines
1.4 KiB
using System;
|
|
using FluentMigrator;
|
|
using NUnit.Framework;
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
using NzbDrone.Test.Common.AutoMoq;
|
|
|
|
namespace NzbDrone.Core.Test.Framework
|
|
{
|
|
[Category("DbMigrationTest")]
|
|
[Category("DbTest")]
|
|
public abstract class MigrationTest<TMigration> : DbTest where TMigration : NzbDroneMigrationBase
|
|
{
|
|
protected long MigrationVersion
|
|
{
|
|
get
|
|
{
|
|
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 =>
|
|
{
|
|
var migration = m as TMigration;
|
|
if (beforeMigration != null && migration is TMigration)
|
|
{
|
|
beforeMigration(migration);
|
|
}
|
|
}
|
|
});
|
|
|
|
return db.GetDirectDataMapper();
|
|
}
|
|
|
|
[SetUp]
|
|
public override void SetupDb()
|
|
{
|
|
SetupContainer();
|
|
}
|
|
|
|
[Obsolete("Don't use Mocker/Repositories in MigrationTests, query the DB.", true)]
|
|
public new AutoMoqer Mocker => base.Mocker;
|
|
}
|
|
} |