2011-12-12 07:22:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-09-01 06:58:54 +00:00
|
|
|
|
using System.Linq;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-09-01 06:58:54 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2012-04-20 06:42:13 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-09-01 06:58:54 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
2012-04-20 06:42:13 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Search;
|
2011-09-01 06:58:54 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-09-01 06:58:54 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 07:27:16 +00:00
|
|
|
|
public class SeasonSearchJobTest : CoreTest
|
2011-09-01 06:58:54 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void SeasonSearch_full_season_success()
|
|
|
|
|
{
|
|
|
|
|
var notification = new ProgressNotification("Season Search");
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(true);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, 1, 1);
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once());
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Never());
|
|
|
|
|
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Times.Never());
|
2011-09-01 06:58:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SeasonSearch_partial_season_success()
|
|
|
|
|
{
|
2012-04-20 06:42:13 +00:00
|
|
|
|
var resultItems = Builder<SearchResultItem>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SearchError = ReportRejectionType.None)
|
|
|
|
|
.With(e => e.Success = true)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-01 06:58:54 +00:00
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5)
|
2011-10-18 21:46:06 +00:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.With(e => e.SeriesId = 5)
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Season Search");
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false);
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes);
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1))
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Returns(resultItems.ToList());
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, 1, 1);
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once());
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
|
|
|
|
|
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Times.Never());
|
2011-09-01 06:58:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SeasonSearch_partial_season_failure()
|
|
|
|
|
{
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5)
|
2011-10-18 21:46:06 +00:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.Ignored = false)
|
2011-12-12 07:22:28 +00:00
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Season Search");
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false);
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes);
|
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
2011-09-01 06:58:54 +00:00
|
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1))
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Returns(new List<SearchResultItem>{ new SearchResultItem{ Success = true }});
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
2011-12-12 07:22:28 +00:00
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, 1, 1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once());
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Season Search");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
|
|
|
|
.Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
|
|
|
|
.Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SearchProvider>()
|
|
|
|
|
.Setup(c => c.PartialSeasonSearch(notification, 1, 1))
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Returns(new List<SearchResultItem> { new SearchResultItem { Success = false, SearchError = ReportRejectionType.Size} });
|
2011-12-12 07:22:28 +00:00
|
|
|
|
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.Resolve<SeasonSearchJob>().Start(notification, 1, 1);
|
2011-09-01 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-12 07:22:28 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once());
|
|
|
|
|
Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
|
2011-09-01 06:58:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|