1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 10:17:47 +00:00
Sonarr/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs
2011-12-01 21:14:59 -08:00

110 lines
No EOL
4.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SeasonSearchJobTest : CoreTest
{
[Test]
public void SeasonSearch_full_season_success()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SearchProvider>()
.Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(true);
//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.Never());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Times.Never());
}
[Test]
public void SeasonSearch_partial_season_success()
{
var episodes = Builder<Episode>.CreateListOfSize(5)
.All()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
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))
.Returns(episodes.Select(e => e.EpisodeNumber).ToList());
//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());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Times.Never());
}
[Test]
public void SeasonSearch_partial_season_failure()
{
var episodes = Builder<Episode>.CreateListOfSize(5)
.All()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 1)
.With(e => e.Ignored = false)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
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))
.Returns(new List<int>{1});
mocker.GetMock<EpisodeSearchJob>()
.Setup(c => c.Start(notification, It.IsAny<int>(), 0)).Verifiable();
//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());
mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Times.Exactly(4));
}
}
}