From 2a1f9500eb6fcf210520bf0f1bec145936378030 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 31 Mar 2013 23:49:46 -0700 Subject: [PATCH] updated migration logger --- NzbDrone.Core.Test/Framework/DbTest.cs | 4 +- .../IndexerTests/NzbxFixture.cs | 11 --- .../JobTests/JobRepositoryFixture.cs | 34 +++++----- NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs | 36 ---------- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 - .../DiskScanProviderTests/ScanFixture.cs | 67 ------------------- .../Migration/Framework/MigrationLogger.cs | 52 ++++++++++++++ .../Migration/Framework/NlogAnnouncer.cs | 15 ----- NzbDrone.Core/NzbDrone.Core.csproj | 2 +- 9 files changed, 70 insertions(+), 153 deletions(-) delete mode 100644 NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs delete mode 100644 NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs create mode 100644 NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs delete mode 100644 NzbDrone.Core/Datastore/Migration/Framework/NlogAnnouncer.cs diff --git a/NzbDrone.Core.Test/Framework/DbTest.cs b/NzbDrone.Core.Test/Framework/DbTest.cs index 86fa4408a..5186e25d1 100644 --- a/NzbDrone.Core.Test/Framework/DbTest.cs +++ b/NzbDrone.Core.Test/Framework/DbTest.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Data; using System.IO; using System.Linq; using Marr.Data; using NUnit.Framework; -using NzbDrone.Common; using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Migration.Framework; @@ -96,7 +94,7 @@ namespace NzbDrone.Core.Test.Framework MapRepository.Instance.EnableTraceLogging = true; - var factory = new DbFactory(new MigrationController(new NlogAnnouncer())); + var factory = new DbFactory(new MigrationController(new MigrationLogger(TestLogger))); _database = factory.Create(_dbName, MigrationType); _db = new TestTestDatabase(_database); Mocker.SetConstant(_database); diff --git a/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs b/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs index e93e6a80e..7cb417ee3 100644 --- a/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs +++ b/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs @@ -1,22 +1,11 @@ using System; -using System.Globalization; -using System.IO; -using System.Linq; using System.Net; -using System.ServiceModel.Syndication; -using System.Threading; -using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Indexers; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; - using NzbDrone.Core.Test.Framework; -using NzbDrone.Core.Test.ProviderTests; -using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.IndexerTests { diff --git a/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs b/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs index 25f50dff2..ad111ac6e 100644 --- a/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs +++ b/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs @@ -1,19 +1,11 @@ - - -using System.Linq; +using System.Linq; using System; using System.Collections.Generic; -using System.Threading; using FizzWare.NBuilder; using FluentAssertions; -using NCrunch.Framework; using NUnit.Framework; -using NzbDrone.Common; using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model; - using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.JobTests { @@ -56,37 +48,43 @@ namespace NzbDrone.Core.Test.JobTests IEnumerable fakeJobs = new List { _fakeJob }; Mocker.SetConstant(fakeJobs); - Subject.Init(); - var deletedJob = Builder.CreateNew() - .With(c => c.Id = 0) - .Build(); + .With(c => c.Id = 0) + .Build(); Db.Insert(deletedJob); + + //Make sure deleted job is stored + AllStoredModels.Should().HaveCount(1); + AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type); + Subject.Init(); + //Make sure init has cleaned up the deleted job AllStoredModels.Should().HaveCount(1); AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); } [Test] - public void inti_should_removed_jobs_that_no_longer_exist_even_with_same_name() + public void init_should_removed_jobs_that_no_longer_exist_even_with_same_name() { IEnumerable fakeJobs = new List { _fakeJob }; Mocker.SetConstant(fakeJobs); - Subject.Init(); - var deletedJob = Builder.CreateNew() .With(c => c.Name = _fakeJob.Name) .With(c => c.Id = 0) .Build(); - Db.Insert(deletedJob); - Subject.Init(); + //Make sure deleted job is stored + AllStoredModels.Should().HaveCount(1); + AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type); + + Subject.Init(); + //Make sure init has cleaned up the deleted job AllStoredModels.Should().HaveCount(1); AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); } diff --git a/NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs b/NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs deleted file mode 100644 index e98f2eef2..000000000 --- a/NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Jobs.Implementations; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; - -namespace NzbDrone.Core.Test.JobTests -{ - [TestFixture] - - public class RssSyncJobTest : CoreTest - { - public void WithMinutes(int minutes) - { - Mocker.GetMock().SetupGet(s => s.RssSyncInterval).Returns(minutes); - } - - [TestCase(10)] - [TestCase(15)] - [TestCase(25)] - [TestCase(60)] - [TestCase(120)] - public void should_use_value_from_config_provider(int minutes) - { - WithMinutes(minutes); - Mocker.Resolve().DefaultInterval.Should().Be(TimeSpan.FromMinutes(minutes)); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index f6a2400b9..f2eae1dff 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -170,7 +170,6 @@ - @@ -179,7 +178,6 @@ - diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs deleted file mode 100644 index 382c02641..000000000 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using FizzWare.NBuilder; -using Moq; -using NUnit.Framework; -using NzbDrone.Common; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common; - -namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests -{ - - public class ScanFixture : CoreTest - { - [Test] - public void series_should_update_the_last_scan_date() - { - - - Mocker.GetMock() - .Setup(c => c.Update(It.Is(s => s.LastDiskSync != null))).Verifiable(); - - Mocker.GetMock() - .Setup(c => c.GetEpisodeBySeries(It.IsAny())) - .Returns(new List { new Episode() }); - - Mocker.GetMock() - .Setup(c => c.FolderExists(It.IsAny())) - .Returns(true); - - Mocker.GetMock() - .Setup(c => c.GetFilesBySeries(It.IsAny())) - .Returns(new List()); - - Mocker.Resolve().Scan(new Series()); - - Mocker.VerifyAllMocks(); - - } - - [Test] - public void series_should_log_warning_if_path_doesnt_exist_on_disk() - { - - WithStrictMocker(); - - var series = Builder.CreateNew() - .With(s => s.Path = @"C:\Test\TV\SeriesName\") - .Build(); - - - Mocker.GetMock() - .Setup(c => c.FolderExists(series.Path)) - .Returns(false); - - - Mocker.Resolve().Scan(series, series.Path); - - - Mocker.VerifyAllMocks(); - ExceptionVerification.ExpectedWarns(1); - } - } -} diff --git a/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs b/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs new file mode 100644 index 000000000..cab90b90c --- /dev/null +++ b/NzbDrone.Core/Datastore/Migration/Framework/MigrationLogger.cs @@ -0,0 +1,52 @@ +using System; +using FluentMigrator.Runner; +using NLog; + +namespace NzbDrone.Core.Datastore.Migration.Framework +{ + public class MigrationLogger : IAnnouncer + { + private readonly Logger _logger; + + + public MigrationLogger(Logger logger) + { + _logger = logger; + } + + + public void Heading(string message) + { + _logger.Info("*** {0} ***", message); + } + + public void Say(string message) + { + _logger.Debug(message); + } + + public void Emphasize(string message) + { + _logger.Warn(message); + } + + public void Sql(string sql) + { + _logger.Trace(sql); + } + + public void ElapsedTime(TimeSpan timeSpan) + { + } + + public void Error(string message) + { + _logger.Error(message); + } + + public void Write(string message, bool escaped) + { + _logger.Info(message); + } + } +} diff --git a/NzbDrone.Core/Datastore/Migration/Framework/NlogAnnouncer.cs b/NzbDrone.Core/Datastore/Migration/Framework/NlogAnnouncer.cs deleted file mode 100644 index c108151e8..000000000 --- a/NzbDrone.Core/Datastore/Migration/Framework/NlogAnnouncer.cs +++ /dev/null @@ -1,15 +0,0 @@ -using FluentMigrator.Runner.Announcers; -using NLog; - -namespace NzbDrone.Core.Datastore.Migration.Framework -{ - public class NlogAnnouncer : Announcer - { - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - - public override void Write(string message, bool escaped) - { - logger.Info(message); - } - } -} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 743f48ac7..57c15ee9a 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -208,7 +208,7 @@ - +