2011-10-21 02:42:17 +03:00
|
|
|
using System.Collections.Generic;
|
2011-08-28 22:07:56 +03:00
|
|
|
using System.Linq;
|
2011-11-14 03:22:18 +03:00
|
|
|
|
2011-08-28 22:07:56 +03:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-08-28 22:07:56 +03:00
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-08-28 22:07:56 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class BacklogSearchJobTest
|
|
|
|
{
|
|
|
|
[Test]
|
2011-10-09 05:16:11 +03:00
|
|
|
public void no_missing_epsiodes_should_not_trigger_any_search()
|
2011-08-28 22:07:56 +03:00
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var notification = new ProgressNotification("Backlog Search Job Test");
|
|
|
|
|
|
|
|
var episodes = new List<Episode>();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
|
|
|
|
Times.Never());
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
|
|
|
|
Times.Never());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2011-10-09 05:16:11 +03:00
|
|
|
public void individual_missing_episode()
|
2011-08-28 22:07:56 +03:00
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var notification = new ProgressNotification("Backlog Search Job Test");
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(1).Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>()
|
|
|
|
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
|
|
|
|
Times.Never());
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
|
|
|
|
Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void individual_missing_episodes_only()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var notification = new ProgressNotification("Backlog Search Job Test");
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5).Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>()
|
|
|
|
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
|
|
|
|
Times.Never());
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
|
|
|
|
Times.Exactly(episodes.Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void series_season_missing_episodes_only_mismatch_count()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var notification = new ProgressNotification("Backlog Search Job Test");
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
2011-08-28 22:07:56 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>()
|
|
|
|
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
2011-10-20 08:05:04 +03:00
|
|
|
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
2011-08-28 22:07:56 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
|
|
|
|
Times.Never());
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
|
|
|
|
Times.Exactly(episodes.Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void series_season_missing_episodes_only()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var notification = new ProgressNotification("Backlog Search Job Test");
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
2011-08-28 22:07:56 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
|
|
|
|
|
|
|
mocker.GetMock<SeasonSearchJob>()
|
|
|
|
.Setup(s => s.Start(notification, It.IsAny<int>(), It.IsAny<int>())).Verifiable();
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList());
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
|
|
|
|
Times.Once());
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
|
|
|
|
Times.Never());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void multiple_missing_episodes()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var notification = new ProgressNotification("Backlog Search Job Test");
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.TheFirst(5)
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
2011-08-28 22:07:56 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
|
|
|
|
|
|
|
|
mocker.GetMock<SeasonSearchJob>()
|
|
|
|
.Setup(s => s.Start(notification, It.IsAny<int>(), It.IsAny<int>())).Verifiable();
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>()
|
|
|
|
.Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
2011-10-20 08:05:04 +03:00
|
|
|
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5 });
|
2011-08-28 22:07:56 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
|
|
|
|
Times.Once());
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
|
|
|
|
Times.Exactly(5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|