mirror of https://github.com/Radarr/Radarr
Some test cleanup
This commit is contained in:
parent
633f0b6197
commit
82b6ec5ed4
|
@ -1,5 +1,6 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using AutoMoq;
|
using AutoMoq;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
@ -10,7 +11,6 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
public class TestBase : LoggingTest
|
public class TestBase : LoggingTest
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
{
|
{
|
||||||
|
|
||||||
static TestBase()
|
static TestBase()
|
||||||
{
|
{
|
||||||
InitLogging();
|
InitLogging();
|
||||||
|
@ -57,10 +57,16 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
Mocker = new AutoMoqer();
|
Mocker = new AutoMoqer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void WithStrictMocker()
|
||||||
|
{
|
||||||
|
Mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDownBase()
|
public void TearDownBase()
|
||||||
{
|
{
|
||||||
ExceptionVerification.AssertNoUnexcpectedLogs();
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
||||||
|
Mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,14 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class BannerDownloadJobTest : TestBase
|
public class BannerDownloadJobTest : TestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
WithStrictMocker();
|
||||||
|
WithTempAsStartUpPath();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void BannerDownload_all()
|
public void BannerDownload_all()
|
||||||
{
|
{
|
||||||
|
@ -26,28 +34,25 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.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())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(fakeSeries.Count));
|
Times.Exactly(fakeSeries.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,28 +65,25 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.With(s => s.BannerUrl = null)
|
.With(s => s.BannerUrl = null)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
var notification = new ProgressNotification("Banner Download");
|
||||||
mocker.Resolve<EnviromentProvider>();
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
Mocker.GetMock<SeriesProvider>()
|
||||||
|
|
||||||
mocker.GetMock<SeriesProvider>()
|
|
||||||
.Setup(c => c.GetAllSeries())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(8));
|
Times.Exactly(8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,67 +94,64 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
||||||
var pathProvider = Mocker.Resolve<PathProvider>();
|
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
var pathProvider = Mocker.Resolve<PathProvider>();
|
||||||
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())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "2.jpg")));
|
.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")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "3.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "4.jpg")));
|
.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")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "5.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "6.jpg")));
|
.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")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "7.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "8.jpg")));
|
.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")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "9.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "10.jpg")));
|
.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>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(fakeSeries.Count));
|
Times.Exactly(fakeSeries.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,29 +162,26 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.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())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(fakeSeries.Count));
|
Times.Exactly(fakeSeries.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,29 +193,26 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.With(s => s.SeriesId = 1)
|
.With(s => s.SeriesId = 1)
|
||||||
.Build();
|
.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.GetSeries(1))
|
.Setup(c => c.GetSeries(1))
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Once());
|
Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,20 +224,18 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.With(s => s.SeriesId = 1)
|
.With(s => s.SeriesId = 1)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
Mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Once());
|
Times.Once());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ using PetaPoco;
|
||||||
namespace NzbDrone.Core.Test
|
namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
[Explicit]
|
||||||
[Category("Benchmark")]
|
[Category("Benchmark")]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class DbBenchmark : TestBase
|
public class DbBenchmark : TestBase
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
|
|
||||||
public virtual void DownloadBanner(ProgressNotification notification, Series series)
|
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);
|
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace NzbDrone.Core
|
||||||
_jobProvider = jobProvider;
|
_jobProvider = jobProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Make timer doesn't keep running during unit tests.
|
||||||
public void StartTimer(int secondInterval)
|
public void StartTimer(int secondInterval)
|
||||||
{
|
{
|
||||||
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
|
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
|
||||||
|
|
Loading…
Reference in New Issue