2013-04-15 03:41:39 +02:00
|
|
|
|
using System.Collections.Generic;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2013-08-12 08:00:40 +02:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
2013-02-23 22:29:22 +01:00
|
|
|
|
using NzbDrone.Core.History;
|
2013-08-08 05:30:20 +02:00
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 03:41:39 +02:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2013-02-19 07:01:03 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-02-19 03:19:38 +01:00
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-03-07 02:51:47 +01:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
2013-02-19 03:19:38 +01:00
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-15 03:41:39 +02:00
|
|
|
|
public class UpgradeHistorySpecificationFixture : CoreTest<UpgradeHistorySpecification>
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
private UpgradeHistorySpecification _upgradeHistory;
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
private RemoteEpisode _parseResultMulti;
|
|
|
|
|
private RemoteEpisode _parseResultSingle;
|
2013-03-27 01:51:37 +01:00
|
|
|
|
private QualityModel _upgradableQuality;
|
|
|
|
|
private QualityModel _notupgradableQuality;
|
|
|
|
|
private Series _fakeSeries;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-03-07 01:19:49 +01:00
|
|
|
|
Mocker.Resolve<QualityUpgradableSpecification>();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
_upgradeHistory = Mocker.Resolve<UpgradeHistorySpecification>();
|
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
var singleEpisodeList = new List<Episode> { new Episode { Id = 1, SeasonNumber = 12, EpisodeNumber = 3 } };
|
2012-10-17 09:39:06 +02:00
|
|
|
|
var doubleEpisodeList = new List<Episode> {
|
2013-03-27 01:51:37 +01:00
|
|
|
|
new Episode {Id = 1, SeasonNumber = 12, EpisodeNumber = 3 },
|
|
|
|
|
new Episode {Id = 2, SeasonNumber = 12, EpisodeNumber = 4 },
|
|
|
|
|
new Episode {Id = 3, SeasonNumber = 12, EpisodeNumber = 5 }
|
2012-10-17 09:39:06 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_fakeSeries = Builder<Series>.CreateNew()
|
2013-02-27 04:19:22 +01:00
|
|
|
|
.With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p })
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Build();
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
_parseResultMulti = new RemoteEpisode
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Series = _fakeSeries,
|
2013-04-28 21:46:13 +02:00
|
|
|
|
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
2012-10-17 09:39:06 +02:00
|
|
|
|
Episodes = doubleEpisodeList
|
2012-02-07 06:08:07 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
_parseResultSingle = new RemoteEpisode
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Series = _fakeSeries,
|
2013-04-28 21:46:13 +02:00
|
|
|
|
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
2012-10-17 09:39:06 +02:00
|
|
|
|
Episodes = singleEpisodeList
|
2012-02-07 06:08:07 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_upgradableQuality = new QualityModel(Quality.SDTV, false);
|
|
|
|
|
_notupgradableQuality = new QualityModel(Quality.HDTV1080p, true);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_notupgradableQuality);
|
|
|
|
|
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_notupgradableQuality);
|
2013-03-25 02:38:11 +01:00
|
|
|
|
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(3)).Returns<QualityModel>(null);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithFirstReportUpgradable()
|
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithSecondReportUpgradable()
|
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_upgradableQuality);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_upgradable_if_only_episode_is_upgradable()
|
|
|
|
|
{
|
|
|
|
|
WithFirstReportUpgradable();
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_upgradable_if_both_episodes_are_upgradable()
|
|
|
|
|
{
|
|
|
|
|
WithFirstReportUpgradable();
|
|
|
|
|
WithSecondReportUpgradable();
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeTrue();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
|
|
|
|
|
{
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
|
|
|
|
|
{
|
|
|
|
|
WithFirstReportUpgradable();
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
|
|
|
|
|
{
|
|
|
|
|
WithSecondReportUpgradable();
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
2012-12-13 17:43:25 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing()
|
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_fakeSeries.QualityProfile = new QualityProfile { Cutoff = Quality.WEBDL1080p };
|
2013-04-28 21:46:13 +02:00
|
|
|
|
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, false);
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, false);
|
2012-12-13 17:43:25 +01:00
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
|
2012-12-13 17:43:25 +01:00
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
|
2012-12-13 17:43:25 +01:00
|
|
|
|
}
|
2013-08-08 05:30:20 +02:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_true_if_it_is_a_search()
|
|
|
|
|
{
|
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, new SeasonSearchCriteria()).Should().BeTrue();
|
|
|
|
|
}
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|