using System; using System.Collections.Generic; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming public class BannerDownloadJobTest : TestBase { [Test] public void BannerDownload_all() { //Setup var fakeSeries = Builder.CreateListOfSize(10) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Banner Download"); mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Returns(true); mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act mocker.Resolve().Start(notification, 0, 0); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(fakeSeries.Count)); } [Test] public void BannerDownload_some_null_BannerUrl() { //Setup var fakeSeries = Builder.CreateListOfSize(10) .WhereRandom(2) .Have(s => s.BannerUrl = null) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Banner Download"); mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Returns(true); mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act mocker.Resolve().Start(notification, 0, 0); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(8)); } [Test] public void BannerDownload_some_failed_download() { //Setup var fakeSeries = Builder.CreateListOfSize(10) .Build(); const string path = @"C:\Users\mark.mcdowall\Dropbox\Visual Studio 2010\NzbDrone\NzbDrone.Core.Test\bin\Debug\Content\Images\Banners\"; var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Banner Download"); mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "1.jpg")) .Returns(false); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "2.jpg")) .Returns(true); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "3.jpg")) .Returns(false); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "4.jpg")) .Returns(true); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "5.jpg")) .Returns(false); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "6.jpg")) .Returns(true); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "7.jpg")) .Returns(false); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "8.jpg")) .Returns(true); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "9.jpg")) .Returns(false); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), path + "10.jpg")) .Returns(true); mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act mocker.Resolve().Start(notification, 0, 0); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(fakeSeries.Count)); } [Test] public void BannerDownload_all_failed_download() { //Setup var fakeSeries = Builder.CreateListOfSize(10) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Banner Download"); mocker.GetMock() .Setup(c => c.GetAllSeries()) .Returns(fakeSeries); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Returns(false); mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act mocker.Resolve().Start(notification, 0, 0); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Exactly(fakeSeries.Count)); } [Test] public void BannerDownload_single_banner() { //Setup var fakeSeries = Builder.CreateNew() .With(s => s.SeriesId = 1) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Banner Download"); mocker.GetMock() .Setup(c => c.GetSeries(1)) .Returns(fakeSeries); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Returns(true); mocker.GetMock() .Setup(S => S.CreateDirectory(It.IsAny())) .Returns(""); //Act mocker.Resolve().Start(notification, 1, 0); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Once()); } [Test] public void Download_Banner() { //Setup var fakeSeries = Builder.CreateNew() .With(s => s.SeriesId = 1) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Banner Download"); mocker.GetMock() .Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) .Returns(true); //Act mocker.Resolve().DownloadBanner(notification, fakeSeries); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(s => s.DownloadFile(It.IsAny(), It.IsAny()), Times.Once()); } } }