2017-08-27 20:24:44 +00:00
|
|
|
using System;
|
2015-10-07 05:22:37 +00:00
|
|
|
using System.Collections.Generic;
|
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;
|
2020-01-03 12:49:24 +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;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
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
|
|
|
{
|
2020-01-03 12:49:24 +00:00
|
|
|
private const int FIRST_ALBUM_ID = 1;
|
|
|
|
private const int SECOND_ALBUM_ID = 2;
|
|
|
|
|
2013-10-24 05:13:04 +00:00
|
|
|
private HistorySpecification _upgradeHistory;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
private RemoteAlbum _parseResultMulti;
|
|
|
|
private RemoteAlbum _parseResultSingle;
|
2019-08-02 11:50:09 +00:00
|
|
|
private QualityModel _upgradableQuality;
|
|
|
|
private QualityModel _notupgradableQuality;
|
2017-08-14 02:58:42 +00:00
|
|
|
private Artist _fakeArtist;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2017-09-04 02:20:56 +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
|
|
|
|
2019-08-02 11:50:09 +00:00
|
|
|
var singleAlbumList = new List<Album> { new Album { Id = FIRST_ALBUM_ID } };
|
2020-01-03 12:49:24 +00:00
|
|
|
var doubleAlbumList = new List<Album>
|
|
|
|
{
|
|
|
|
new Album { Id = FIRST_ALBUM_ID },
|
|
|
|
new Album { Id = SECOND_ALBUM_ID },
|
|
|
|
new Album { Id = 3 }
|
|
|
|
};
|
2012-10-17 07:39:06 +00:00
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_fakeArtist = Builder<Artist>.CreateNew()
|
2019-02-23 22:39:11 +00:00
|
|
|
.With(c => c.QualityProfile = new QualityProfile
|
|
|
|
{
|
|
|
|
UpgradeAllowed = true,
|
|
|
|
Cutoff = Quality.MP3_320.Id,
|
|
|
|
Items = Qualities.QualityFixture.GetDefaultQualities()
|
|
|
|
})
|
|
|
|
.Build();
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_parseResultMulti = new RemoteAlbum
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
Artist = _fakeArtist,
|
2019-08-02 11:50:09 +00:00
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
2017-08-14 02:58:42 +00:00
|
|
|
Albums = doubleAlbumList
|
2012-02-07 05:08:07 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_parseResultSingle = new RemoteAlbum
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
Artist = _fakeArtist,
|
2019-08-02 11:50:09 +00:00
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
|
2017-08-14 02:58:42 +00:00
|
|
|
Albums = singleAlbumList
|
2012-02-07 05:08:07 +00:00
|
|
|
};
|
|
|
|
|
2019-08-02 11:50:09 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.MP3_192, new Revision(version: 1));
|
|
|
|
_notupgradableQuality = new QualityModel(Quality.MP3_320, 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
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
private void GivenMostRecentForAlbum(int albumId, string downloadId, QualityModel quality, DateTime date, EntityHistoryEventType eventType)
|
2015-10-07 05:22:37 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForAlbum(albumId))
|
2021-12-25 01:55:32 +00:00
|
|
|
.Returns(new EntityHistory { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType });
|
2015-10-07 05:22:37 +00:00
|
|
|
}
|
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()
|
|
|
|
{
|
2017-08-27 20:24:44 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, new AlbumSearchCriteria()).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
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
Mocker.GetMock<IHistoryService>().Setup(s => s.MostRecentForAlbum(It.IsAny<int>())).Returns((EntityHistory)null);
|
2015-10-07 05:22:37 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, 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
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.DownloadFailed);
|
2015-10-07 05:22:37 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 12:49:24 +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
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-12).AddMilliseconds(-1), EntityHistoryEventType.Grabbed);
|
2015-10-07 05:22:37 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
2013-10-24 05:13:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_be_upgradable_if_only_album_is_upgradable()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_be_upgradable_if_both_albums_are_upgradable()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForAlbum(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.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]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_not_be_upgradable_if_both_albums_are_not_upgradable()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForAlbum(SECOND_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.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]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_be_not_upgradable_if_only_first_albums_is_upgradable()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.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]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_be_not_upgradable_if_only_second_albums_is_upgradable()
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
|
|
|
GivenMostRecentForAlbum(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
2014-10-27 05:51:50 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
2012-12-13 16:43:25 +00:00
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_not_be_upgradable_if_album_is_of_same_quality_as_existing()
|
2012-12-13 16:43:25 +00:00
|
|
|
{
|
2019-02-23 22:39:11 +00:00
|
|
|
_fakeArtist.QualityProfile = new QualityProfile { Cutoff = Quality.MP3_320.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
2017-11-21 00:20:21 +00:00
|
|
|
_parseResultSingle.ParsedAlbumInfo.Quality = new QualityModel(Quality.MP3_320, new Revision(version: 1));
|
2019-08-02 11:50:09 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.MP3_320, new Revision(version: 1));
|
2012-12-13 16:43:25 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.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-02-23 22:39:11 +00:00
|
|
|
_fakeArtist.QualityProfile = new QualityProfile { Cutoff = Quality.MP3_320.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
2017-11-21 00:20:21 +00:00
|
|
|
_parseResultSingle.ParsedAlbumInfo.Quality = new QualityModel(Quality.MP3_320, new Revision(version: 1));
|
2019-08-02 11:50:09 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.MP3_320, new Revision(version: 1));
|
2015-10-15 07:23:14 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed);
|
2015-10-15 07:23:14 +00:00
|
|
|
|
|
|
|
_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()
|
|
|
|
{
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), EntityHistoryEventType.Grabbed);
|
2015-10-18 18:01:26 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, 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();
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), EntityHistoryEventType.Grabbed);
|
2015-10-19 18:42:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_if_cutoff_already_met_and_cdh_is_disabled()
|
|
|
|
{
|
|
|
|
GivenCdhDisabled();
|
2019-02-23 22:39:11 +00:00
|
|
|
_fakeArtist.QualityProfile = new QualityProfile { Cutoff = Quality.MP3_320.Id, Items = Qualities.QualityFixture.GetDefaultQualities() };
|
2017-11-21 00:20:21 +00:00
|
|
|
_parseResultSingle.ParsedAlbumInfo.Quality = new QualityModel(Quality.MP3_320, new Revision(version: 1));
|
2019-08-02 11:50:09 +00:00
|
|
|
_upgradableQuality = new QualityModel(Quality.MP3_320, new Revision(version: 1));
|
2015-10-19 18:42:05 +00:00
|
|
|
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), EntityHistoryEventType.Grabbed);
|
2015-10-19 18:42:05 +00:00
|
|
|
|
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2017-08-14 02:58:42 +00:00
|
|
|
public void should_return_false_if_only_album_is_not_upgradable_and_cdh_is_disabled()
|
2015-10-19 18:42:05 +00:00
|
|
|
{
|
|
|
|
GivenCdhDisabled();
|
2021-12-25 01:55:32 +00:00
|
|
|
GivenMostRecentForAlbum(FIRST_ALBUM_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), EntityHistoryEventType.Grabbed);
|
2015-10-19 18:42:05 +00:00
|
|
|
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
2015-10-07 05:22:37 +00:00
|
|
|
}
|