2018-02-26 15:08:44 +00:00
|
|
|
using System;
|
2012-02-07 05:08:07 +00:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
2013-10-24 05:13:04 +00:00
|
|
|
using Moq;
|
2012-02-07 05:08:07 +00:00
|
|
|
using NUnit.Framework;
|
2015-10-19 18:42:05 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-08-12 06:00:40 +00:00
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
2013-02-23 21:29:22 +00:00
|
|
|
using NzbDrone.Core.History;
|
2013-08-08 03:30:20 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Profiles;
|
2013-02-27 03:19:22 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
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-10-24 05:13:04 +00:00
|
|
|
public class HistorySpecificationFixture : CoreTest<HistorySpecification>
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
private const int FIRST_EPISODE_ID = 1;
|
|
|
|
private const int SECOND_EPISODE_ID = 2;
|
|
|
|
|
2013-10-24 05:13:04 +00:00
|
|
|
private HistorySpecification _upgradeHistory;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
private RemoteMovie _parseResultSingle;
|
2013-03-27 00:51:37 +00:00
|
|
|
private QualityModel _upgradableQuality;
|
|
|
|
private QualityModel _notupgradableQuality;
|
2018-03-14 20:41:36 +00:00
|
|
|
private Movie _fakeMovie;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2019-06-19 02:50:17 +00:00
|
|
|
Mocker.Resolve<UpgradableSpecification>();
|
2013-10-24 05:13:04 +00:00
|
|
|
_upgradeHistory = Mocker.Resolve<HistorySpecification>();
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
_fakeMovie = Builder<Movie>.CreateNew()
|
2019-06-11 02:59:39 +00:00
|
|
|
.With(c => c.Profile = new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() })
|
2012-02-07 05:08:07 +00:00
|
|
|
.Build();
|
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
_parseResultSingle = new RemoteMovie
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2018-03-14 20:41:36 +00:00
|
|
|
Movie = _fakeMovie,
|
|
|
|
ParsedMovieInfo = new ParsedMovieInfo { Quality = new QualityModel(Quality.DVD, new Revision(version: 2)) }
|
2012-02-07 05:08:07 +00:00
|
|
|
};
|
|
|
|
|
2014-09-01 02:28:42 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.SDTV, new Revision(version: 1));
|
|
|
|
_notupgradableQuality = new QualityModel(Quality.HDTV1080p, new Revision(version: 2));
|
2015-10-19 18:42:05 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IConfigService>()
|
|
|
|
.SetupGet(s => s.EnableCompletedDownloadHandling)
|
|
|
|
.Returns(true);
|
2015-10-07 05:22:37 +00:00
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2015-10-07 05:22:37 +00:00
|
|
|
private void GivenMostRecentForEpisode(int episodeId, string downloadId, QualityModel quality, DateTime date, HistoryEventType eventType)
|
|
|
|
{
|
2018-02-26 15:08:44 +00:00
|
|
|
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForMovie(episodeId))
|
2015-10-07 05:22:37 +00:00
|
|
|
.Returns(new History.History { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType });
|
|
|
|
}
|
2013-10-23 06:36:31 +00:00
|
|
|
|
2015-10-19 18:42:05 +00:00
|
|
|
private void GivenCdhDisabled()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IConfigService>()
|
|
|
|
.SetupGet(s => s.EnableCompletedDownloadHandling)
|
|
|
|
.Returns(false);
|
|
|
|
}
|
|
|
|
|
2015-10-07 05:22:37 +00:00
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_it_is_a_search()
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, new MovieSearchCriteria()).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-07 05:22:37 +00:00
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_latest_history_item_is_null()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2018-02-26 15:08:44 +00:00
|
|
|
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForMovie(It.IsAny<int>())).Returns((History.History)null);
|
2018-08-05 14:28:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-07 05:22:37 +00:00
|
|
|
[Test]
|
|
|
|
public void should_return_true_if_latest_history_item_is_not_grabbed()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.DownloadFailed);
|
2018-08-05 14:28:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
// [Test]
|
|
|
|
// public void should_return_true_if_latest_history_has_a_download_id_and_cdh_is_enabled()
|
|
|
|
// {
|
|
|
|
// GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
|
|
|
// _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
|
|
|
// }
|
2015-10-07 05:22:37 +00:00
|
|
|
[Test]
|
2015-10-18 17:54:16 +00:00
|
|
|
public void should_return_true_if_latest_history_item_is_older_than_twelve_hours()
|
2013-10-24 05:13:04 +00:00
|
|
|
{
|
2015-10-18 18:01:26 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-13), HistoryEventType.Grabbed);
|
2018-08-05 14:28:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
2013-10-24 05:13:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
[Test]
|
|
|
|
public void should_be_upgradable_if_only_episode_is_upgradable()
|
|
|
|
{
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
/*
|
2012-02-07 05:08:07 +00:00
|
|
|
[Test]
|
|
|
|
public void should_be_upgradable_if_both_episodes_are_upgradable()
|
|
|
|
{
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForEpisode(SECOND_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
|
|
|
|
{
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForEpisode(SECOND_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
|
|
|
|
{
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
|
|
|
|
{
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForEpisode(SECOND_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
2018-08-05 14:28:05 +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()
|
|
|
|
{
|
2019-06-11 02:59:39 +00:00
|
|
|
_fakeMovie.Profile = new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
2018-03-14 20:41:36 +00:00
|
|
|
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
|
2014-09-01 02:28:42 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
|
2012-12-13 16:43:25 +00:00
|
|
|
|
2015-10-07 05:22:37 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
2012-12-13 16:43:25 +00:00
|
|
|
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
2012-12-13 16:43:25 +00:00
|
|
|
}
|
2015-10-15 07:23:14 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_upgradable_if_cutoff_already_met()
|
|
|
|
{
|
2019-06-11 02:59:39 +00:00
|
|
|
_fakeMovie.Profile = new Profile { Cutoff = Quality.WEBDL1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
2018-03-14 20:41:36 +00:00
|
|
|
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
|
2015-10-15 07:23:14 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1));
|
|
|
|
|
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed);
|
|
|
|
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
|
|
|
}
|
2015-10-18 17:52:26 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_latest_history_item_is_only_one_hour_old()
|
|
|
|
{
|
2015-10-18 18:01:26 +00:00
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), HistoryEventType.Grabbed);
|
2018-08-05 14:28:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
2015-10-18 17:52:26 +00:00
|
|
|
}
|
2015-10-19 18:42:05 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_latest_history_has_a_download_id_and_cdh_is_disabled()
|
|
|
|
{
|
|
|
|
GivenCdhDisabled();
|
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
2018-08-05 14:28:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
2015-10-19 18:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_cutoff_already_met_and_cdh_is_disabled()
|
|
|
|
{
|
|
|
|
GivenCdhDisabled();
|
2019-06-11 02:59:39 +00:00
|
|
|
_fakeMovie.Profile = new Profile { Cutoff = Quality.WEBDL1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
2018-03-14 20:41:36 +00:00
|
|
|
_parseResultSingle.ParsedMovieInfo.Quality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1));
|
2015-10-19 18:42:05 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, new Revision(version: 1));
|
|
|
|
|
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
|
|
|
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_only_episode_is_not_upgradable_and_cdh_is_disabled()
|
|
|
|
{
|
|
|
|
GivenCdhDisabled();
|
|
|
|
GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed);
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
2015-10-07 05:22:37 +00:00
|
|
|
}
|