Some test cleanup

pull/7/merge
kay.one 13 years ago
parent 633f0b6197
commit 82b6ec5ed4

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

@ -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<Series>.CreateListOfSize(10)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
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<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(8));
}
@ -92,67 +94,64 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var pathProvider = Mocker.Resolve<PathProvider>();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var pathProvider = Mocker.Resolve<PathProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "2.jpg")));
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "3.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "4.jpg")));
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "5.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "6.jpg")));
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "7.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "8.jpg")));
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "9.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "10.jpg")));
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(fakeSeries.Count));
}
@ -163,29 +162,26 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Throws(new WebException());
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
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<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(1))
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Throws(new WebException());
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
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<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Throws(new WebException());
//Act
mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
Mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Once());
}
}

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

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

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

Loading…
Cancel
Save