From c55ca42c21d211c0ecda2f5af51c451e93a186cb Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 16 Oct 2011 19:03:54 -0700 Subject: [PATCH] Migration is no longer executed per test, its ran once and the db is cloned after that, (faster tests, cleaner logs ;) --- NzbDrone.Core.Test/Framework/Fixtures.cs | 6 +++--- NzbDrone.Core.Test/Framework/MockLib.cs | 19 +++++++++++++------ NzbDrone.Core.Test/dbBenchmark.cs | 1 + NzbDrone.Core/Datastore/MigrationsHelper.cs | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/NzbDrone.Core.Test/Framework/Fixtures.cs b/NzbDrone.Core.Test/Framework/Fixtures.cs index 4d16f35ba..30e514579 100644 --- a/NzbDrone.Core.Test/Framework/Fixtures.cs +++ b/NzbDrone.Core.Test/Framework/Fixtures.cs @@ -21,8 +21,7 @@ namespace NzbDrone.Core.Test { try { - LogManager.Configuration = - new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); + LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); LogManager.ThrowExceptions = true; var exceptionVerification = new ExceptionVerification(); @@ -35,7 +34,6 @@ namespace NzbDrone.Core.Test Console.WriteLine("Unable to configure logging. " + e); } - var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories); foreach (var file in filesToDelete) { @@ -45,6 +43,8 @@ namespace NzbDrone.Core.Test } catch { } } + + MockLib.CreateDataBaseTemplate(); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Framework/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs index c220858f1..237372d9b 100644 --- a/NzbDrone.Core.Test/Framework/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -17,20 +17,19 @@ namespace NzbDrone.Core.Test.Framework /// internal static class MockLib { - public static string[] StandardSeries - { - get { return new[] { "c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24" }; } - } + private const string DbTemplateName = "_dbtemplate.sdf"; 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)) { fileName = Guid.NewGuid() + ".sdf"; } + File.Copy(DbTemplateName, fileName); + var connectionString = Connection.GetConnectionString(fileName); var database = Connection.GetPetaPocoDb(connectionString); @@ -38,7 +37,15 @@ namespace NzbDrone.Core.Test.Framework return database; } - public static Series GetFakeSeries(int id, string title) + 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) { return Builder.CreateNew() .With(c => c.SeriesId = id) diff --git a/NzbDrone.Core.Test/dbBenchmark.cs b/NzbDrone.Core.Test/dbBenchmark.cs index 3b8b3800b..80a35b06c 100644 --- a/NzbDrone.Core.Test/dbBenchmark.cs +++ b/NzbDrone.Core.Test/dbBenchmark.cs @@ -15,6 +15,7 @@ using PetaPoco; namespace NzbDrone.Core.Test { [TestFixture] + [Category("Benchmark")] // ReSharper disable InconsistentNaming public class DbBenchmark : TestBase { diff --git a/NzbDrone.Core/Datastore/MigrationsHelper.cs b/NzbDrone.Core/Datastore/MigrationsHelper.cs index b5b74ab8e..0267ce58b 100644 --- a/NzbDrone.Core/Datastore/MigrationsHelper.cs +++ b/NzbDrone.Core/Datastore/MigrationsHelper.cs @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Datastore EnsureDatabase(connetionString); - Logger.Info("Preparing to run database migration"); + Logger.Trace("Preparing to run database migration"); try {