2011-10-20 23:42:17 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-08-23 05:29:12 +00:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-08-23 05:29:12 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2012-09-11 06:35:25 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-08-23 05:29:12 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class SeriesSearchJobTest : CoreTest
|
2011-08-23 05:29:12 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void SeriesSearch_success()
|
|
|
|
|
{
|
2011-08-28 06:37:34 +00:00
|
|
|
|
var seasons = new List<int> { 1, 2, 3, 4, 5 };
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
WithStrictMocker();
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Series Search");
|
|
|
|
|
|
2013-02-24 20:24:31 +00:00
|
|
|
|
Mocker.GetMock<ISeasonRepository>()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.Setup(c => c.GetSeasonNumbers(1)).Returns(seasons);
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
2013-02-24 20:24:31 +00:00
|
|
|
|
Mocker.GetMock<ISeasonRepository>()
|
2011-08-28 19:24:16 +00:00
|
|
|
|
.Setup(c => c.IsIgnored(It.IsAny<int>(), It.IsAny<int>())).Returns(false);
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.GetMock<SeasonSearchJob>()
|
2012-09-11 06:35:25 +00:00
|
|
|
|
.Setup(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == 1 && d.GetPropertyValue<int>("SeasonNumber") >= 0))).Verifiable();
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<SeriesSearchJob>().Start(notification, new { SeriesId = 1 });
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2012-09-11 06:35:25 +00:00
|
|
|
|
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == 1 && d.GetPropertyValue<int>("SeasonNumber") >= 0)),
|
2011-08-28 06:37:34 +00:00
|
|
|
|
Times.Exactly(seasons.Count));
|
2011-08-23 05:29:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-08-28 06:37:34 +00:00
|
|
|
|
public void SeriesSearch_no_seasons()
|
2011-08-23 05:29:12 +00:00
|
|
|
|
{
|
2011-08-28 06:37:34 +00:00
|
|
|
|
var seasons = new List<int>();
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
WithStrictMocker();
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Series Search");
|
|
|
|
|
|
2013-02-24 20:24:31 +00:00
|
|
|
|
Mocker.GetMock<ISeasonRepository>()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.Setup(c => c.GetSeasonNumbers(1)).Returns(seasons);
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<SeriesSearchJob>().Start(notification, new { SeriesId = 1 });
|
2011-08-23 05:29:12 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny<int>() }),
|
2011-08-28 06:37:34 +00:00
|
|
|
|
Times.Never());
|
2011-08-23 05:29:12 +00:00
|
|
|
|
}
|
2011-11-26 07:52:54 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SeriesSearch_should_not_search_for_season_0()
|
|
|
|
|
{
|
2013-02-24 20:24:31 +00:00
|
|
|
|
Mocker.GetMock<ISeasonRepository>()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.Setup(c => c.GetSeasonNumbers(It.IsAny<int>()))
|
2011-11-26 07:52:54 +00:00
|
|
|
|
.Returns(new List<int> { 0, 1, 2 });
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<SeriesSearchJob>().Start(MockNotification, new { SeriesId = 12 });
|
2011-11-26 07:52:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SeasonSearchJob>()
|
2012-09-10 19:04:17 +00:00
|
|
|
|
.Verify(c => c.Start(It.IsAny<ProgressNotification>(), new { SeriesId = It.IsAny<int>(), SeasonNumber = 0 }), Times.Never());
|
2011-11-26 07:52:54 +00:00
|
|
|
|
}
|
2011-08-23 05:29:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|