2018-03-14 20:41:36 +00:00
|
|
|
using System;
|
2014-06-08 08:22:55 +00:00
|
|
|
using System.Collections.Generic;
|
2019-12-22 22:08:53 +00:00
|
|
|
using System.Linq;
|
2014-06-08 08:22:55 +00:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
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;
|
|
|
|
using NzbDrone.Core.Download.Pending;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2023-08-15 02:20:03 +00:00
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2014-07-27 00:39:28 +00:00
|
|
|
public class AddFixture : CoreTest<PendingReleaseService>
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
private DownloadDecision _temporarilyRejected;
|
2017-03-06 21:23:25 +00:00
|
|
|
private Movie _movie;
|
2023-08-15 02:20:03 +00:00
|
|
|
private QualityProfile _profile;
|
2014-06-08 08:22:55 +00:00
|
|
|
private ReleaseInfo _release;
|
2019-12-22 21:24:10 +00:00
|
|
|
private ParsedMovieInfo _parsedMovieInfo;
|
2017-03-06 21:23:25 +00:00
|
|
|
private RemoteMovie _remoteMovie;
|
2019-06-14 03:54:25 +00:00
|
|
|
private List<PendingRelease> _heldReleases;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
_movie = Builder<Movie>.CreateNew()
|
2014-06-08 08:22:55 +00:00
|
|
|
.Build();
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2023-08-15 02:20:03 +00:00
|
|
|
_profile = new QualityProfile
|
2019-12-22 22:08:53 +00:00
|
|
|
{
|
|
|
|
Name = "Test",
|
|
|
|
Cutoff = Quality.HDTV720p.Id,
|
2023-08-15 02:20:03 +00:00
|
|
|
Items = new List<QualityProfileQualityItem>
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
2023-08-15 02:20:03 +00:00
|
|
|
new QualityProfileQualityItem { Allowed = true, Quality = Quality.HDTV720p },
|
|
|
|
new QualityProfileQualityItem { Allowed = true, Quality = Quality.WEBDL720p },
|
|
|
|
new QualityProfileQualityItem { Allowed = true, Quality = Quality.Bluray720p }
|
2014-06-08 08:22:55 +00:00
|
|
|
},
|
2019-12-22 22:08:53 +00:00
|
|
|
};
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2023-08-15 02:20:03 +00:00
|
|
|
_movie.QualityProfile = _profile;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
_release = Builder<ReleaseInfo>.CreateNew().Build();
|
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
_parsedMovieInfo = Builder<ParsedMovieInfo>.CreateNew().Build();
|
|
|
|
_parsedMovieInfo.Quality = new QualityModel(Quality.HDTV720p);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
_remoteMovie = new RemoteMovie();
|
2019-12-22 21:24:10 +00:00
|
|
|
_remoteMovie.Movie = _movie;
|
2017-03-06 21:23:25 +00:00
|
|
|
_remoteMovie.ParsedMovieInfo = _parsedMovieInfo;
|
|
|
|
_remoteMovie.Release = _release;
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
_temporarilyRejected = new DownloadDecision(_remoteMovie, new Rejection("Temp Rejected", RejectionType.Temporary));
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
_heldReleases = new List<PendingRelease>();
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Setup(s => s.All())
|
2019-06-17 02:18:32 +00:00
|
|
|
.Returns(_heldReleases);
|
|
|
|
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Setup(s => s.AllByMovieId(It.IsAny<int>()))
|
|
|
|
.Returns<int>(i => _heldReleases.Where(v => v.MovieId == i).ToList());
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
Mocker.GetMock<IMovieService>()
|
|
|
|
.Setup(s => s.GetMovie(It.IsAny<int>()))
|
|
|
|
.Returns(_movie);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IPrioritizeDownloadDecision>()
|
2018-03-14 20:41:36 +00:00
|
|
|
.Setup(s => s.PrioritizeDecisionsForMovies(It.IsAny<List<DownloadDecision>>()))
|
2014-06-08 08:22:55 +00:00
|
|
|
.Returns((List<DownloadDecision> d) => d);
|
|
|
|
}
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
private void GivenHeldRelease(string title, string indexer, DateTime publishDate, PendingReleaseReason reason = PendingReleaseReason.Delay)
|
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-03-06 21:23:25 +00:00
|
|
|
.With(h => h.MovieId = _movie.Id)
|
2014-06-08 08:22:55 +00:00
|
|
|
.With(h => h.Title = title)
|
|
|
|
.With(h => h.Release = release)
|
2019-06-14 03:54:25 +00:00
|
|
|
.With(h => h.Reason = reason)
|
2022-12-06 03:15:42 +00:00
|
|
|
.With(h => h.ParsedMovieInfo = _parsedMovieInfo)
|
2014-06-08 08:22:55 +00:00
|
|
|
.Build();
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
_heldReleases.AddRange(heldReleases);
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_add()
|
|
|
|
{
|
2019-06-14 03:54:25 +00:00
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Delay);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
VerifyInsert();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_add_if_it_is_the_same_release_from_the_same_indexer()
|
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate);
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Delay);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
VerifyNoInsert();
|
|
|
|
}
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
[Test]
|
|
|
|
public void should_not_add_if_it_is_the_same_release_from_the_same_indexer_twice()
|
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate, PendingReleaseReason.DownloadClientUnavailable);
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate, PendingReleaseReason.Fallback);
|
|
|
|
|
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Delay);
|
|
|
|
|
|
|
|
VerifyNoInsert();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_remove_duplicate_if_it_is_the_same_release_from_the_same_indexer_twice()
|
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate, PendingReleaseReason.DownloadClientUnavailable);
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate, PendingReleaseReason.Fallback);
|
|
|
|
|
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Fallback);
|
|
|
|
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Verify(v => v.Delete(It.IsAny<int>()), Times.Once());
|
|
|
|
}
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
[Test]
|
|
|
|
public void should_add_if_title_is_different()
|
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title + "-RP", _release.Indexer, _release.PublishDate);
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Delay);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
VerifyInsert();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_add_if_indexer_is_different()
|
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, "AnotherIndexer", _release.PublishDate);
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Delay);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
VerifyInsert();
|
|
|
|
}
|
2014-07-27 00:39:28 +00:00
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
[Test]
|
|
|
|
public void should_add_if_publish_date_is_different()
|
|
|
|
{
|
|
|
|
GivenHeldRelease(_release.Title, _release.Indexer, _release.PublishDate.AddHours(1));
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
Subject.Add(_temporarilyRejected, PendingReleaseReason.Delay);
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
VerifyInsert();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void VerifyInsert()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Verify(v => v.Insert(It.IsAny<PendingRelease>()), Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void VerifyNoInsert()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IPendingReleaseRepository>()
|
|
|
|
.Verify(v => v.Insert(It.IsAny<PendingRelease>()), Times.Never());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|