1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-25 17:27:59 +00:00

Migration is no longer executed per test, its ran once and the db is cloned after that, (faster tests, cleaner logs ;)

This commit is contained in:
kay.one 2011-10-16 19:03:54 -07:00
parent f1248d12c6
commit c55ca42c21
4 changed files with 18 additions and 10 deletions

View file

@ -21,8 +21,7 @@ public void SetUp()
{ {
try try
{ {
LogManager.Configuration = LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false);
new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false);
LogManager.ThrowExceptions = true; LogManager.ThrowExceptions = true;
var exceptionVerification = new ExceptionVerification(); var exceptionVerification = new ExceptionVerification();
@ -35,7 +34,6 @@ public void SetUp()
Console.WriteLine("Unable to configure logging. " + e); Console.WriteLine("Unable to configure logging. " + e);
} }
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories); var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
foreach (var file in filesToDelete) foreach (var file in filesToDelete)
{ {
@ -45,6 +43,8 @@ public void SetUp()
} }
catch { } catch { }
} }
MockLib.CreateDataBaseTemplate();
} }
} }
} }

View file

@ -17,20 +17,19 @@ namespace NzbDrone.Core.Test.Framework
/// </summary> /// </summary>
internal static class MockLib internal static class MockLib
{ {
public static string[] StandardSeries private const string DbTemplateName = "_dbtemplate.sdf";
{
get { return new[] { "c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24" }; }
}
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "") public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
{ {
Console.WriteLine("Creating an empty PetaPoco database"); Console.WriteLine("Cloning database from template.");
if (String.IsNullOrWhiteSpace(fileName)) if (String.IsNullOrWhiteSpace(fileName))
{ {
fileName = Guid.NewGuid() + ".sdf"; fileName = Guid.NewGuid() + ".sdf";
} }
File.Copy(DbTemplateName, fileName);
var connectionString = Connection.GetConnectionString(fileName); var connectionString = Connection.GetConnectionString(fileName);
var database = Connection.GetPetaPocoDb(connectionString); var database = Connection.GetPetaPocoDb(connectionString);
@ -38,6 +37,14 @@ public static IDatabase GetEmptyDatabase(bool enableLogging = false, string file
return database; return database;
} }
public static void CreateDataBaseTemplate()
{
Console.WriteLine("Creating an empty PetaPoco database");
var connectionString = Connection.GetConnectionString(DbTemplateName);
var database = Connection.GetPetaPocoDb(connectionString);
database.Dispose();
}
public static Series GetFakeSeries(int id, string title) public static Series GetFakeSeries(int id, string title)
{ {
return Builder<Series>.CreateNew() return Builder<Series>.CreateNew()

View file

@ -15,6 +15,7 @@
namespace NzbDrone.Core.Test namespace NzbDrone.Core.Test
{ {
[TestFixture] [TestFixture]
[Category("Benchmark")]
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public class DbBenchmark : TestBase public class DbBenchmark : TestBase
{ {

View file

@ -20,7 +20,7 @@ public static void Run(string connetionString, bool trace)
EnsureDatabase(connetionString); EnsureDatabase(connetionString);
Logger.Info("Preparing to run database migration"); Logger.Trace("Preparing to run database migration");
try try
{ {