From 82b6ec5ed4b95257bb776f2b9f64a6e2c84f4061 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 3 Nov 2011 16:23:54 -0700 Subject: [PATCH] Some test cleanup --- NzbDrone.Core.Test/Framework/TestBase.cs | 8 +- .../JobTests/BannerDownloadJobTest.cs | 115 ++++++++---------- NzbDrone.Core.Test/dbBenchmark.cs | 1 + .../Providers/Jobs/BannerDownloadJob.cs | 2 +- NzbDrone.Core/WebTimer.cs | 1 + 5 files changed, 63 insertions(+), 64 deletions(-) diff --git a/NzbDrone.Core.Test/Framework/TestBase.cs b/NzbDrone.Core.Test/Framework/TestBase.cs index 427b01c5c..9fc833d3a 100644 --- a/NzbDrone.Core.Test/Framework/TestBase.cs +++ b/NzbDrone.Core.Test/Framework/TestBase.cs @@ -1,5 +1,6 @@ using System.IO; using AutoMoq; +using Moq; using NUnit.Framework; using Ninject; using NzbDrone.Common; @@ -10,7 +11,6 @@ namespace NzbDrone.Core.Test.Framework public class TestBase : LoggingTest // ReSharper disable InconsistentNaming { - static TestBase() { InitLogging(); @@ -57,10 +57,16 @@ namespace NzbDrone.Core.Test.Framework Mocker = new AutoMoqer(); } + protected void WithStrictMocker() + { + Mocker = new AutoMoqer(MockBehavior.Strict); + } + [TearDown] public void TearDownBase() { ExceptionVerification.AssertNoUnexcpectedLogs(); + Mocker = new AutoMoqer(MockBehavior.Strict); } diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index 59b50e506..3f37ffe38 100644 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -19,6 +19,14 @@ namespace NzbDrone.Core.Test.JobTests // ReSharper disable InconsistentNaming public class BannerDownloadJobTest : TestBase { + + [SetUp] + public void Setup() + { + WithStrictMocker(); + WithTempAsStartUpPath(); + } + [Test] public void BannerDownload_all() { @@ -26,28 +34,25 @@ namespace NzbDrone.Core.Test.JobTests var fakeSeries = Builder.CreateListOfSize(10) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.Resolve(); - var notification = new ProgressNotification("Banner Download"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())); - mocker.GetMock() + Mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act - mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, 0, 0); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(fakeSeries.Count)); } @@ -60,28 +65,25 @@ namespace NzbDrone.Core.Test.JobTests .With(s => s.BannerUrl = null) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.Resolve(); + var notification = new ProgressNotification("Banner Download"); - var notification = new ProgressNotification("Banner Download"); - - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())); - mocker.GetMock() + Mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act - mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, 0, 0); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(8)); } @@ -92,67 +94,64 @@ namespace NzbDrone.Core.Test.JobTests var fakeSeries = Builder.CreateListOfSize(10) .Build(); - - var pathProvider = Mocker.Resolve(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.Resolve(); + var pathProvider = Mocker.Resolve(); var notification = new ProgressNotification("Banner Download"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "1.jpg"))) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "2.jpg"))); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "3.jpg"))) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "4.jpg"))); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "5.jpg"))) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "6.jpg"))); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "7.jpg"))) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "8.jpg"))); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "9.jpg"))) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), Path.Combine(pathProvider.BannerPath, "10.jpg"))); - mocker.GetMock() + Mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act - mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, 0, 0); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(fakeSeries.Count)); } @@ -163,29 +162,26 @@ namespace NzbDrone.Core.Test.JobTests var fakeSeries = Builder.CreateListOfSize(10) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.Resolve(); - var notification = new ProgressNotification("Banner Download"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act - mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, 0, 0); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(fakeSeries.Count)); } @@ -197,29 +193,26 @@ namespace NzbDrone.Core.Test.JobTests .With(s => s.SeriesId = 1) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - mocker.Resolve(); - var notification = new ProgressNotification("Banner Download"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetSeries(1)) .Returns(fakeSeries); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Throws(new WebException()); - mocker.GetMock() + Mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act - mocker.Resolve().Start(notification, 1, 0); + Mocker.Resolve().Start(notification, 1, 0); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Once()); } @@ -231,20 +224,18 @@ namespace NzbDrone.Core.Test.JobTests .With(s => s.SeriesId = 1) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - var notification = new ProgressNotification("Banner Download"); - mocker.GetMock() + Mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Throws(new WebException()); //Act - mocker.Resolve().DownloadBanner(notification, fakeSeries); + Mocker.Resolve().DownloadBanner(notification, fakeSeries); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Once()); } } diff --git a/NzbDrone.Core.Test/dbBenchmark.cs b/NzbDrone.Core.Test/dbBenchmark.cs index de2b63b49..66fae0a9f 100644 --- a/NzbDrone.Core.Test/dbBenchmark.cs +++ b/NzbDrone.Core.Test/dbBenchmark.cs @@ -15,6 +15,7 @@ using PetaPoco; namespace NzbDrone.Core.Test { [TestFixture] + [Explicit] [Category("Benchmark")] // ReSharper disable InconsistentNaming public class DbBenchmark : TestBase diff --git a/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs b/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs index 8f8da8622..f90e73748 100644 --- a/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs +++ b/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Providers.Jobs public virtual void DownloadBanner(ProgressNotification notification, Series series) { - var bannerFilename = Path.Combine(_pathProvider.BannerPath, series.SeriesId.ToString(), ".jpg"); + var bannerFilename = Path.Combine(_pathProvider.BannerPath, series.SeriesId.ToString()) + ".jpg"; notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title); diff --git a/NzbDrone.Core/WebTimer.cs b/NzbDrone.Core/WebTimer.cs index 03d940da6..e9872407a 100644 --- a/NzbDrone.Core/WebTimer.cs +++ b/NzbDrone.Core/WebTimer.cs @@ -18,6 +18,7 @@ namespace NzbDrone.Core _jobProvider = jobProvider; } + //TODO: Make timer doesn't keep running during unit tests. public void StartTimer(int secondInterval) { _onCacheRemove = new CacheItemRemovedCallback(DoWork);