2017-09-04 02:20:56 +00:00
|
|
|
using System;
|
2014-06-08 08:22:55 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Marr.Data;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2015-01-27 05:57:07 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2014-12-03 00:47:45 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Download.Pending;
|
2014-12-03 00:47:45 +00:00
|
|
|
using NzbDrone.Core.Indexers;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2017-08-14 02:58:42 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2014-07-27 00:39:28 +00:00
|
|
|
public class RemoveRejectedFixture : CoreTest<PendingReleaseService>
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
private DownloadDecision _temporarilyRejected;
|
2017-08-14 02:58:42 +00:00
|
|
|
private Artist _artist;
|
|
|
|
private Album _album;
|
2014-06-08 08:22:55 +00:00
|
|
|
private Profile _profile;
|
|
|
|
private ReleaseInfo _release;
|
2017-08-14 02:58:42 +00:00
|
|
|
private ParsedAlbumInfo _parsedAlbumInfo;
|
|
|
|
private RemoteAlbum _remoteAlbum;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
_artist = Builder<Artist>.CreateNew()
|
2014-06-08 08:22:55 +00:00
|
|
|
.Build();
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_album = Builder<Album>.CreateNew()
|
2014-06-08 08:22:55 +00:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
_profile = new Profile
|
|
|
|
{
|
|
|
|
Name = "Test",
|
2017-11-16 02:24:33 +00:00
|
|
|
Cutoff = Quality.MP3_192.Id,
|
2014-06-08 08:22:55 +00:00
|
|
|
Items = new List<ProfileQualityItem>
|
|
|
|
{
|
2017-07-03 18:39:06 +00:00
|
|
|
new ProfileQualityItem { Allowed = true, Quality = Quality.MP3_192 },
|
|
|
|
new ProfileQualityItem { Allowed = true, Quality = Quality.MP3_256 },
|
|
|
|
new ProfileQualityItem { Allowed = true, Quality = Quality.MP3_320 }
|
2014-06-08 08:22:55 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_artist.Profile = new LazyLoaded<Profile>(_profile);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
_release = Builder<ReleaseInfo>.CreateNew().Build();
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_parsedAlbumInfo = Builder<ParsedAlbumInfo>.CreateNew().Build();
|
|
|
|
_parsedAlbumInfo.Quality = new QualityModel(Quality.MP3_192);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_remoteAlbum = new RemoteAlbum();
|
|
|
|
_remoteAlbum.Albums = new List<Album>{ _album };
|
|
|
|
_remoteAlbum.Artist = _artist;
|
|
|
|
_remoteAlbum.ParsedAlbumInfo = _parsedAlbumInfo;
|
|
|
|
_remoteAlbum.Release = _release;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
_temporarilyRejected = new DownloadDecision(_remoteAlbum, new Rejection("Temp Rejected", RejectionType.Temporary));
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Setup(s => s.All())
|
|
|
|
.Returns(new List<PendingRelease>());
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
Mocker.GetMock<IArtistService>()
|
|
|
|
.Setup(s => s.GetArtist(It.IsAny<int>()))
|
|
|
|
.Returns(_artist);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
2017-08-14 02:58:42 +00:00
|
|
|
.Setup(s => s.GetAlbums(It.IsAny<ParsedAlbumInfo>(), _artist, null))
|
|
|
|
.Returns(new List<Album> {_album});
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IPrioritizeDownloadDecision>()
|
|
|
|
.Setup(s => s.PrioritizeDecisions(It.IsAny<List<DownloadDecision>>()))
|
|
|
|
.Returns((List<DownloadDecision> d) => d);
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private void GivenHeldRelease(string title, string indexer, DateTime publishDate)
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
var release = _release.JsonClone();
|
|
|
|
release.Indexer = indexer;
|
|
|
|
release.PublishDate = publishDate;
|
|
|
|
|
|
|
|
|
|
|
|
var heldReleases = Builder<PendingRelease>.CreateListOfSize(1)
|
|
|
|
.All()
|
2017-08-14 02:58:42 +00:00
|
|
|
.With(h => h.ArtistId = _artist.Id)
|
2014-06-08 08:22:55 +00:00
|
|
|
.With(h => h.Title = title)
|
|
|
|
.With(h => h.Release = release)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Setup(s => s.All())
|
|
|
|
.Returns(heldReleases);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2014-07-27 00:39:28 +00:00
|
|
|
public void should_remove_if_it_is_the_same_release_from_the_same_indexer()
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate);
|
|
|
|
|
2014-12-03 00:47:45 +00:00
|
|
|
Subject.Handle(new RssSyncCompleteEvent(new ProcessedDecisions(new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision> { _temporarilyRejected })));
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2014-07-27 00:39:28 +00:00
|
|
|
VerifyDelete();
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2014-07-27 00:39:28 +00:00
|
|
|
public void should_not_remove_if_title_is_different()
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title + "-RP", _release.Indexer, _release.PublishDate);
|
|
|
|
|
2014-12-03 00:47:45 +00:00
|
|
|
Subject.Handle(new RssSyncCompleteEvent(new ProcessedDecisions(new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision> { _temporarilyRejected })));
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2014-07-27 00:39:28 +00:00
|
|
|
VerifyNoDelete();
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2014-07-27 00:39:28 +00:00
|
|
|
public void should_not_remove_if_indexer_is_different()
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, "AnotherIndexer", _release.PublishDate);
|
|
|
|
|
2014-12-03 00:47:45 +00:00
|
|
|
Subject.Handle(new RssSyncCompleteEvent(new ProcessedDecisions(new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision> { _temporarilyRejected })));
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2014-07-27 00:39:28 +00:00
|
|
|
VerifyNoDelete();
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
2014-07-27 00:39:28 +00:00
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
[Test]
|
2014-07-27 00:39:28 +00:00
|
|
|
public void should_not_remove_if_publish_date_is_different()
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate.AddHours(1));
|
|
|
|
|
2014-12-03 00:47:45 +00:00
|
|
|
Subject.Handle(new RssSyncCompleteEvent(new ProcessedDecisions(new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision>(),
|
|
|
|
new List<DownloadDecision> { _temporarilyRejected })));
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2014-07-27 00:39:28 +00:00
|
|
|
VerifyNoDelete();
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
2014-07-27 00:39:28 +00:00
|
|
|
private void VerifyDelete()
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
2014-07-27 00:39:28 +00:00
|
|
|
.Verify(v => v.Delete(It.IsAny<PendingRelease>()), Times.Once());
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
2014-07-27 00:39:28 +00:00
|
|
|
private void VerifyNoDelete()
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
2014-07-27 00:39:28 +00:00
|
|
|
.Verify(v => v.Delete(It.IsAny<PendingRelease>()), Times.Never());
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|