using System; using System.Collections.Generic; using System.Linq; 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.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 SeasonSearchJobTest : TestBase { [Test] public void SeasonSearch_full_season_success() { var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Season Search"); mocker.GetMock() .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(true); //Act mocker.Resolve().Start(notification, 1, 1); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Never()); mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); } [Test] public void SeasonSearch_partial_season_success() { var episodes = Builder.CreateListOfSize(5) .WhereAll() .Have(e => e.SeriesId = 1) .Have(e => e.SeasonNumber = 1) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Season Search"); mocker.GetMock() .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false); mocker.GetMock() .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes); mocker.GetMock() .Setup(c => c.PartialSeasonSearch(notification, 1, 1)) .Returns(episodes.Select(e => e.EpisodeNumber).ToList()); //Act mocker.Resolve().Start(notification, 1, 1); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); } [Test] public void SeasonSearch_partial_season_failure() { var episodes = Builder.CreateListOfSize(5) .WhereAll() .Have(e => e.SeriesId = 1) .Have(e => e.SeasonNumber = 1) .Have(e => e.Ignored = false) .Build(); var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Season Search"); mocker.GetMock() .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false); mocker.GetMock() .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes); mocker.GetMock() .Setup(c => c.PartialSeasonSearch(notification, 1, 1)) .Returns(new List{1}); mocker.GetMock() .Setup(c => c.Start(notification, It.IsAny(), 0)).Verifiable(); //Act mocker.Resolve().Start(notification, 1, 1); //Assert mocker.VerifyAllMocks(); mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Exactly(4)); } } }