mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-22 22:15:17 -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:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentMigrator;
|
||||
@@ -7,11 +8,11 @@ using FluentMigrator.Runner;
|
||||
using Marr.Data;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Test.Framework
|
||||
{
|
||||
public abstract class DbTest<TSubject, TModel> : DbTest
|
||||
@@ -70,7 +71,6 @@ namespace NzbDrone.Core.Test.Framework
|
||||
get
|
||||
{
|
||||
return MigrationType.Main;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +85,10 @@ namespace NzbDrone.Core.Test.Framework
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual TestDatabase WithTestDb(Action<MigrationBase> beforeMigration)
|
||||
protected virtual ITestDatabase WithTestDb(MigrationContext migrationContext)
|
||||
{
|
||||
var factory = Mocker.Resolve<DbFactory>();
|
||||
var database = factory.Create(MigrationType, beforeMigration);
|
||||
var database = factory.Create(migrationContext);
|
||||
Mocker.SetConstant(database);
|
||||
|
||||
switch (MigrationType)
|
||||
@@ -118,7 +118,6 @@ namespace NzbDrone.Core.Test.Framework
|
||||
return testDb;
|
||||
}
|
||||
|
||||
|
||||
protected void SetupContainer()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
@@ -134,7 +133,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||
public virtual void SetupDb()
|
||||
{
|
||||
SetupContainer();
|
||||
_db = WithTestDb(null);
|
||||
_db = WithTestDb(new MigrationContext(MigrationType));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -158,57 +157,4 @@ namespace NzbDrone.Core.Test.Framework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ITestDatabase
|
||||
{
|
||||
void InsertMany<T>(IEnumerable<T> items) where T : ModelBase, new();
|
||||
T Insert<T>(T item) where T : ModelBase, new();
|
||||
List<T> All<T>() where T : ModelBase, new();
|
||||
T Single<T>() where T : ModelBase, new();
|
||||
void Update<T>(T childModel) where T : ModelBase, new();
|
||||
void Delete<T>(T childModel) where T : ModelBase, new();
|
||||
}
|
||||
|
||||
public class TestDatabase : ITestDatabase
|
||||
{
|
||||
private readonly IDatabase _dbConnection;
|
||||
private IEventAggregator _eventAggregator;
|
||||
|
||||
public TestDatabase(IDatabase dbConnection)
|
||||
{
|
||||
_eventAggregator = new Mock<IEventAggregator>().Object;
|
||||
_dbConnection = dbConnection;
|
||||
}
|
||||
|
||||
public void InsertMany<T>(IEnumerable<T> items) where T : ModelBase, new()
|
||||
{
|
||||
new BasicRepository<T>(_dbConnection, _eventAggregator).InsertMany(items.ToList());
|
||||
}
|
||||
|
||||
public T Insert<T>(T item) where T : ModelBase, new()
|
||||
{
|
||||
return new BasicRepository<T>(_dbConnection, _eventAggregator).Insert(item);
|
||||
}
|
||||
|
||||
public List<T> All<T>() where T : ModelBase, new()
|
||||
{
|
||||
return new BasicRepository<T>(_dbConnection, _eventAggregator).All().ToList();
|
||||
}
|
||||
|
||||
public T Single<T>() where T : ModelBase, new()
|
||||
{
|
||||
return All<T>().SingleOrDefault();
|
||||
}
|
||||
|
||||
public void Update<T>(T childModel) where T : ModelBase, new()
|
||||
{
|
||||
new BasicRepository<T>(_dbConnection, _eventAggregator).Update(childModel);
|
||||
}
|
||||
|
||||
public void Delete<T>(T childModel) where T : ModelBase, new()
|
||||
{
|
||||
new BasicRepository<T>(_dbConnection, _eventAggregator).Delete(childModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user