using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Core.Download; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.Download { [TestFixture] public class DownloadServiceFixture : CoreTest { private RemoteEpisode _parseResult; [SetUp] public void Setup() { Mocker.GetMock() .Setup(c => c.GetDownloadClient()).Returns(Mocker.GetMock().Object); var episodes = Builder.CreateListOfSize(2) .TheFirst(1).With(s => s.Id = 12) .TheNext(1).With(s => s.Id = 99) .All().With(s => s.SeriesId = 5) .Build().ToList(); _parseResult = Builder.CreateNew() .With(c => c.Series = Builder.CreateNew().Build()) .With(c => c.Report = Builder.CreateNew().Build()) .With(c => c.Episodes = episodes) .Build(); Mocker.GetMock().Setup(c => c.IsConfigured).Returns(true); } private void WithSuccessfulAdd() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny())) .Returns(true); } private void WithFailedAdd() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny())) .Returns(false); } [Test] public void Download_report_should_publish_on_grab_event() { WithSuccessfulAdd(); Subject.DownloadReport(_parseResult); VerifyEventPublished(); } [Test] public void Download_report_should_grab_using_client() { WithSuccessfulAdd(); Subject.DownloadReport(_parseResult); Mocker.GetMock() .Verify(s => s.DownloadNzb(It.IsAny()), Times.Once()); } [Test] public void Download_report_should_not_publish_on_failed_grab_event() { WithFailedAdd(); Subject.DownloadReport(_parseResult); VerifyEventNotPublished(); } [Test] public void should_not_attempt_download_if_client_isnt_configure() { Mocker.GetMock().Setup(c => c.IsConfigured).Returns(false); Subject.DownloadReport(_parseResult); Mocker.GetMock().Verify(c => c.DownloadNzb(It.IsAny()),Times.Never()); VerifyEventNotPublished(); ExceptionVerification.ExpectedWarns(1); } } }