updated migration logger

pull/4/head
kay.one 12 years ago
parent 048162a0ef
commit 2a1f9500eb

@ -1,11 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Marr.Data; using Marr.Data;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.Datastore.Migration.Framework;
@ -96,7 +94,7 @@ namespace NzbDrone.Core.Test.Framework
MapRepository.Instance.EnableTraceLogging = true; 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); _database = factory.Create(_dbName, MigrationType);
_db = new TestTestDatabase(_database); _db = new TestTestDatabase(_database);
Mocker.SetConstant(_database); Mocker.SetConstant(_database);

@ -1,22 +1,11 @@
using System; using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.ServiceModel.Syndication;
using System.Threading;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Test.ProviderTests;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.IndexerTests namespace NzbDrone.Core.Test.IndexerTests
{ {

@ -1,19 +1,11 @@
 using System.Linq;
using System.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using NCrunch.Framework;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Jobs; using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.JobTests namespace NzbDrone.Core.Test.JobTests
{ {
@ -56,37 +48,43 @@ namespace NzbDrone.Core.Test.JobTests
IEnumerable<IJob> fakeJobs = new List<IJob> { _fakeJob }; IEnumerable<IJob> fakeJobs = new List<IJob> { _fakeJob };
Mocker.SetConstant(fakeJobs); Mocker.SetConstant(fakeJobs);
Subject.Init();
var deletedJob = Builder<JobDefinition>.CreateNew() var deletedJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Id = 0) .With(c => c.Id = 0)
.Build(); .Build();
Db.Insert(deletedJob); Db.Insert(deletedJob);
//Make sure deleted job is stored
AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type);
Subject.Init(); Subject.Init();
//Make sure init has cleaned up the deleted job
AllStoredModels.Should().HaveCount(1); AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type);
} }
[Test] [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<IJob> fakeJobs = new List<IJob> { _fakeJob }; IEnumerable<IJob> fakeJobs = new List<IJob> { _fakeJob };
Mocker.SetConstant(fakeJobs); Mocker.SetConstant(fakeJobs);
Subject.Init();
var deletedJob = Builder<JobDefinition>.CreateNew() var deletedJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Name = _fakeJob.Name) .With(c => c.Name = _fakeJob.Name)
.With(c => c.Id = 0) .With(c => c.Id = 0)
.Build(); .Build();
Db.Insert(deletedJob); 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().HaveCount(1);
AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type);
} }

@ -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<IConfigService>().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<RssSyncJob>().DefaultInterval.Should().Be(TimeSpan.FromMinutes(minutes));
}
}
}

@ -170,7 +170,6 @@
<Compile Include="Qualities\QualityFixture.cs" /> <Compile Include="Qualities\QualityFixture.cs" />
<Compile Include="EpisodeParseResultTest.cs" /> <Compile Include="EpisodeParseResultTest.cs" />
<Compile Include="JobTests\BacklogSearchJobTest.cs" /> <Compile Include="JobTests\BacklogSearchJobTest.cs" />
<Compile Include="JobTests\RssSyncJobTest.cs" />
<Compile Include="JobTests\PostDownloadScanJobFixture.cs" /> <Compile Include="JobTests\PostDownloadScanJobFixture.cs" />
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" /> <Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
<Compile Include="ParserTests\QualityParserFixture.cs" /> <Compile Include="ParserTests\QualityParserFixture.cs" />
@ -179,7 +178,6 @@
<Compile Include="DecisionEngineTests\CustomStartDateSpecificationFixture.cs" /> <Compile Include="DecisionEngineTests\CustomStartDateSpecificationFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\CleanUpDropFolderFixture.cs" /> <Compile Include="ProviderTests\DiskScanProviderTests\CleanUpDropFolderFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" /> <Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\ScanFixture.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDropDirectoryFixture.cs" /> <Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDropDirectoryFixture.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessVideoFileFixture.cs" /> <Compile Include="ProviderTests\PostDownloadProviderTests\ProcessVideoFileFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" /> <Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" />

@ -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<ISeriesRepository>()
.Setup(c => c.Update(It.Is<Series>(s => s.LastDiskSync != null))).Verifiable();
Mocker.GetMock<IEpisodeService>()
.Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode> { new Episode() });
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IMediaFileService>()
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
.Returns(new List<EpisodeFile>());
Mocker.Resolve<DiskScanProvider>().Scan(new Series());
Mocker.VerifyAllMocks();
}
[Test]
public void series_should_log_warning_if_path_doesnt_exist_on_disk()
{
WithStrictMocker();
var series = Builder<Series>.CreateNew()
.With(s => s.Path = @"C:\Test\TV\SeriesName\")
.Build();
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(series.Path))
.Returns(false);
Mocker.Resolve<DiskScanProvider>().Scan(series, series.Path);
Mocker.VerifyAllMocks();
ExceptionVerification.ExpectedWarns(1);
}
}
}

@ -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);
}
}
}

@ -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);
}
}
}

@ -208,7 +208,7 @@
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" />
<Compile Include="Datastore\Migration\Framework\NlogAnnouncer.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationLogger.cs" />
<Compile Include="Datastore\Migration\Migration20130324.cs" /> <Compile Include="Datastore\Migration\Migration20130324.cs" />
<Compile Include="Datastore\Migration\Framework\NzbDroneMigrationBase.cs" /> <Compile Include="Datastore\Migration\Framework\NzbDroneMigrationBase.cs" />
<Compile Include="Datastore\MigrationType.cs" /> <Compile Include="Datastore\MigrationType.cs" />

Loading…
Cancel
Save