2011-12-12 10:22:28 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2011-09-01 09:58:54 +03:00
|
|
|
using System.Linq;
|
2011-11-14 03:22:18 +03:00
|
|
|
|
2011-09-01 09:58:54 +03:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2012-04-20 09:42:13 +03:00
|
|
|
using NzbDrone.Core.Model;
|
2011-09-01 09:58:54 +03:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Repository;
|
2012-04-20 09:42:13 +03:00
|
|
|
using NzbDrone.Core.Repository.Search;
|
2011-09-01 09:58:54 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2012-12-20 08:43:09 +03:00
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-09-01 09:58:54 +03:00
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-09-01 09:58:54 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 08:44:06 +03:00
|
|
|
public class SeasonSearchJobTest : CoreTest
|
2011-09-01 09:58:54 +03:00
|
|
|
{
|
2012-12-20 08:43:09 +03:00
|
|
|
private IList<Episode> _episodes;
|
|
|
|
|
2012-05-18 02:52:26 +03:00
|
|
|
private ProgressNotification notification;
|
2011-09-01 09:58:54 +03:00
|
|
|
|
2012-05-18 02:52:26 +03:00
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
notification = new ProgressNotification("Search");
|
2012-12-20 08:43:09 +03:00
|
|
|
|
|
|
|
_episodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
|
|
|
.Build();
|
|
|
|
|
2013-02-22 03:47:09 +03:00
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-12-20 08:43:09 +03:00
|
|
|
.Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(_episodes);
|
2011-09-01 09:58:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeasonSearch_partial_season_success()
|
|
|
|
{
|
2012-04-23 10:38:42 +03:00
|
|
|
var resultItems = Builder<SearchHistoryItem>.CreateListOfSize(5)
|
2012-04-20 09:42:13 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SearchError = ReportRejectionType.None)
|
|
|
|
.With(e => e.Success = true)
|
|
|
|
.Build();
|
|
|
|
|
2011-12-12 10:22:28 +03:00
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 09:58:54 +03:00
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1))
|
2012-12-20 08:43:09 +03:00
|
|
|
.Returns(_episodes.Select(e => e.EpisodeNumber).ToList());
|
2011-09-01 09:58:54 +03:00
|
|
|
|
|
|
|
//Act
|
2012-09-10 22:04:17 +03:00
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, new { SeriesId = 1, SeasonNumber = 1 });
|
2011-09-01 09:58:54 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-12 10:22:28 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
|
2012-09-10 22:04:17 +03:00
|
|
|
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny<int>() }), Times.Never());
|
2011-09-01 09:58:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeasonSearch_partial_season_failure()
|
|
|
|
{
|
2011-12-12 10:22:28 +03:00
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 09:58:54 +03:00
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1))
|
2012-04-23 09:31:11 +03:00
|
|
|
.Returns(new List<int>());
|
2011-09-01 09:58:54 +03:00
|
|
|
|
2011-12-12 10:22:28 +03:00
|
|
|
//Act
|
2012-09-10 22:04:17 +03:00
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, new { SeriesId = 1, SeasonNumber = 1 });
|
2011-12-12 10:22:28 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeasonSearch_should_not_search_for_episodes_that_havent_aired_yet_or_air_tomorrow()
|
|
|
|
{
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
|
|
|
.TheLast(2)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(2))
|
|
|
|
.Build();
|
|
|
|
|
2013-02-22 03:47:09 +03:00
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-12-12 10:22:28 +03:00
|
|
|
.Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes);
|
|
|
|
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1))
|
2012-05-18 02:52:26 +03:00
|
|
|
.Returns(new List<int>{1});
|
2011-12-12 10:22:28 +03:00
|
|
|
|
2011-09-01 09:58:54 +03:00
|
|
|
|
|
|
|
//Act
|
2012-09-10 22:04:17 +03:00
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, new { SeriesId = 1, SeasonNumber = 1 });
|
2011-09-01 09:58:54 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-12-12 10:22:28 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
|
2011-09-01 09:58:54 +03:00
|
|
|
}
|
2012-05-04 08:58:42 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeasonSearch_should_allow_searching_of_season_zero()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
2012-05-18 02:52:26 +03:00
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 0)).Returns(new List<int>());
|
2012-05-04 08:58:42 +03:00
|
|
|
|
|
|
|
//Act
|
2012-09-10 22:04:17 +03:00
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, new { SeriesId = 1, SeasonNumber = 0 });
|
2012-05-04 08:58:42 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Never());
|
2012-09-10 22:04:17 +03:00
|
|
|
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny<int>() }), Times.Never());
|
2012-12-20 08:43:09 +03:00
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2012-05-04 08:58:42 +03:00
|
|
|
}
|
2012-12-31 23:25:15 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_search_for_individual_episodes_when_no_partial_results_are_returned()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1)).Returns(new List<int>());
|
|
|
|
|
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, new { SeriesId = 1, SeasonNumber = 1 });
|
|
|
|
|
|
|
|
Mocker.GetMock<EpisodeSearchJob>().Verify(v => v.Start(notification, It.Is<object>(o => o.GetPropertyValue<Int32>("EpisodeId") > 0)), Times.Exactly(_episodes.Count));
|
|
|
|
}
|
2011-09-01 09:58:54 +03:00
|
|
|
}
|
|
|
|
}
|