mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-22 22:16:13 -04:00
Dapper and STJson
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using FluentMigrator;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NUnit.Framework;
|
||||
@@ -11,18 +12,32 @@ namespace NzbDrone.Core.Test.Framework
|
||||
public abstract class MigrationTest<TMigration> : DbTest
|
||||
where TMigration : NzbDroneMigrationBase
|
||||
{
|
||||
protected long MigrationVersion
|
||||
protected long MigrationVersion => ((MigrationAttribute)Attribute.GetCustomAttribute(typeof(TMigration), typeof(MigrationAttribute))).Version;
|
||||
|
||||
[SetUp]
|
||||
public override void SetupDb()
|
||||
{
|
||||
get
|
||||
{
|
||||
var attrib = (MigrationAttribute)Attribute.GetCustomAttribute(typeof(TMigration), typeof(MigrationAttribute));
|
||||
return attrib.Version;
|
||||
}
|
||||
SetupContainer();
|
||||
}
|
||||
|
||||
protected virtual IDirectDataMapper WithMigrationTestDb(Action<TMigration> beforeMigration = null)
|
||||
{
|
||||
var db = WithTestDb(new MigrationContext(MigrationType, MigrationVersion)
|
||||
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<MigrationLoggerProvider>());
|
||||
}
|
||||
|
||||
private ITestDatabase WithMigrationAction(Action<TMigration> beforeMigration = null)
|
||||
{
|
||||
return WithTestDb(new MigrationContext(MigrationType, MigrationVersion)
|
||||
{
|
||||
BeforeMigration = m =>
|
||||
{
|
||||
@@ -32,19 +47,6 @@ namespace NzbDrone.Core.Test.Framework
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return db.GetDirectDataMapper();
|
||||
}
|
||||
|
||||
protected override void SetupLogging()
|
||||
{
|
||||
Mocker.SetConstant<ILoggerProvider>(Mocker.Resolve<MigrationLoggerProvider>());
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public override void SetupDb()
|
||||
{
|
||||
SetupContainer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user