2013-03-28 23:07:09 +01:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2013-03-07 01:19:49 +01:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-02-23 22:29:22 +01:00
|
|
|
|
using NzbDrone.Core.History;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2013-02-19 07:01:03 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
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-02-17 06:44:06 +01:00
|
|
|
|
public class UpgradeHistorySpecificationFixture : CoreTest
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
private UpgradeHistorySpecification _upgradeHistory;
|
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
private EpisodeParseResult _parseResultMulti;
|
|
|
|
|
private EpisodeParseResult _parseResultSingle;
|
|
|
|
|
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-03-27 01:51:37 +01:00
|
|
|
|
_parseResultMulti = new EpisodeParseResult
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Series = _fakeSeries,
|
2013-02-27 04:19:22 +01:00
|
|
|
|
Quality = new QualityModel(Quality.DVD, true),
|
2012-02-07 06:08:07 +01:00
|
|
|
|
EpisodeNumbers = new List<int> { 3, 4 },
|
|
|
|
|
SeasonNumber = 12,
|
2012-10-17 09:39:06 +02:00
|
|
|
|
Episodes = doubleEpisodeList
|
2012-02-07 06:08:07 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_parseResultSingle = new EpisodeParseResult
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
Series = _fakeSeries,
|
2013-02-27 04:19:22 +01:00
|
|
|
|
Quality = new QualityModel(Quality.DVD, true),
|
2012-02-07 06:08:07 +01:00
|
|
|
|
EpisodeNumbers = new List<int> { 3 },
|
|
|
|
|
SeasonNumber = 12,
|
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-03-27 01:51:37 +01:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle).Should().BeTrue();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_upgradable_if_both_episodes_are_upgradable()
|
|
|
|
|
{
|
|
|
|
|
WithFirstReportUpgradable();
|
|
|
|
|
WithSecondReportUpgradable();
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti).Should().BeTrue();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
|
|
|
|
|
{
|
2013-03-27 01:51:37 +01:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti).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-03-27 01:51:37 +01:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti).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-03-27 01:51:37 +01:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti).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 };
|
|
|
|
|
_parseResultSingle.Quality = new QualityModel(Quality.WEBDL1080p, false);
|
|
|
|
|
_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-03-27 01:51:37 +01:00
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle).Should().BeFalse();
|
2012-12-13 17:43:25 +01:00
|
|
|
|
}
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|