1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-22 22:16:13 -04:00

Updated db migration testing framework so we only run migrations up to the one we're testing.

fixes #902
This commit is contained in:
Taloth Saldono
2016-02-13 22:23:37 +01:00
parent 8818e39c63
commit bdb1076100
30 changed files with 710 additions and 333 deletions
@@ -1,23 +1,41 @@
using System;
using System.Data;
using FluentMigrator;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
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 : MigrationBase
public abstract class MigrationTest<TMigration> : DbTest where TMigration : NzbDroneMigrationBase
{
protected override TestDatabase WithTestDb(Action<MigrationBase> beforeMigration)
protected long MigrationVersion
{
return base.WithTestDb(m =>
get
{
if (m.GetType() == typeof(TMigration))
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 =>
{
beforeMigration(m);
var migration = m as TMigration;
if (beforeMigration != null && migration is TMigration)
{
beforeMigration(migration);
}
}
});
return db.GetDirectDataMapper();
}
[SetUp]
@@ -25,5 +43,11 @@ namespace NzbDrone.Core.Test.Framework
{
SetupContainer();
}
[Obsolete("Don't use Mocker/Repositories in MigrationTests, query the DB.", true)]
public new AutoMoqer Mocker
{
get { return base.Mocker; }
}
}
}