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