2013-10-09 06:58:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-10-09 06:07:09 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-10-09 06:58:29 +00:00
|
|
|
|
using NzbDrone.Core.Download;
|
2013-10-09 06:07:09 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
using NzbDrone.Core.Profiles;
|
2013-10-09 06:07:09 +00:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class NotInQueueSpecificationFixture : CoreTest<NotInQueueSpecification>
|
|
|
|
|
{
|
|
|
|
|
private Series _series;
|
|
|
|
|
private Episode _episode;
|
|
|
|
|
private RemoteEpisode _remoteEpisode;
|
|
|
|
|
|
|
|
|
|
private Series _otherSeries;
|
|
|
|
|
private Episode _otherEpisode;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2014-01-18 11:44:36 +00:00
|
|
|
|
_series = Builder<Series>.CreateNew()
|
2014-06-08 08:22:55 +00:00
|
|
|
|
.With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() })
|
2014-01-18 11:44:36 +00:00
|
|
|
|
.Build();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
|
|
|
|
|
_episode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = _series.Id)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_otherSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Id = 2)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_otherEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = _otherSeries.Id)
|
|
|
|
|
.With(e => e.Id = 2)
|
|
|
|
|
.With(e => e.SeasonNumber = 2)
|
|
|
|
|
.With(e => e.EpisodeNumber = 2)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD)})
|
|
|
|
|
.Build();
|
2013-10-09 06:58:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenEmptyQueue()
|
|
|
|
|
{
|
2014-07-19 20:33:12 +00:00
|
|
|
|
Mocker.GetMock<IDownloadTrackingService>()
|
|
|
|
|
.Setup(s => s.GetQueuedDownloads())
|
|
|
|
|
.Returns(new TrackedDownload[0]);
|
2013-10-09 06:58:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 20:33:12 +00:00
|
|
|
|
private void GivenQueue(IEnumerable<RemoteEpisode> remoteEpisodes, TrackedDownloadState state = TrackedDownloadState.Downloading)
|
2013-10-09 06:58:29 +00:00
|
|
|
|
{
|
2014-07-19 20:33:12 +00:00
|
|
|
|
var queue = new List<TrackedDownload>();
|
2013-10-09 06:58:29 +00:00
|
|
|
|
|
|
|
|
|
foreach (var remoteEpisode in remoteEpisodes)
|
|
|
|
|
{
|
2014-07-19 20:33:12 +00:00
|
|
|
|
queue.Add(new TrackedDownload
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2014-07-19 20:33:12 +00:00
|
|
|
|
State = state,
|
2014-09-13 23:13:00 +00:00
|
|
|
|
RemoteEpisode = remoteEpisode
|
2014-07-19 20:33:12 +00:00
|
|
|
|
});
|
2013-10-09 06:58:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 20:33:12 +00:00
|
|
|
|
Mocker.GetMock<IDownloadTrackingService>()
|
|
|
|
|
.Setup(s => s.GetQueuedDownloads())
|
|
|
|
|
.Returns(queue.ToArray());
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_true_when_queue_is_empty()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenEmptyQueue();
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_true_when_series_doesnt_match()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _otherSeries)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 20:33:12 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_true_when_download_is_failed()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.DVD)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode }, TrackedDownloadState.DownloadFailed);
|
|
|
|
|
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2014-07-19 20:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-09 06:07:09 +00:00
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_true_when_quality_in_queue_is_lower()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.SDTV)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_true_when_episode_doesnt_match()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _otherEpisode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.DVD)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_false_when_qualities_are_the_same()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.DVD)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_false_when_quality_in_queue_is_better()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.HDTV720p)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_false_if_matching_multi_episode_is_in_queue()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode, _otherEpisode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.HDTV720p)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_false_if_multi_episode_has_one_episode_in_queue()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.HDTV720p)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_remoteEpisode.Episodes.Add(_otherEpisode);
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_false_if_multi_part_episode_is_already_in_queue()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> { _episode, _otherEpisode })
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality = new QualityModel(Quality.HDTV720p)
|
|
|
|
|
})
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_remoteEpisode.Episodes.Add(_otherEpisode);
|
|
|
|
|
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(new List<RemoteEpisode> { remoteEpisode });
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-10-09 06:58:29 +00:00
|
|
|
|
public void should_return_false_if_multi_part_episode_has_two_episodes_in_queue()
|
2013-10-09 06:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
var remoteEpisodes = Builder<RemoteEpisode>.CreateListOfSize(2)
|
|
|
|
|
.All()
|
|
|
|
|
.With(r => r.Series = _series)
|
|
|
|
|
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
|
{
|
|
|
|
|
Quality =
|
|
|
|
|
new QualityModel(
|
|
|
|
|
Quality.HDTV720p)
|
|
|
|
|
})
|
|
|
|
|
.TheFirst(1)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> {_episode})
|
|
|
|
|
.TheNext(1)
|
|
|
|
|
.With(r => r.Episodes = new List<Episode> {_otherEpisode})
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_remoteEpisode.Episodes.Add(_otherEpisode);
|
2013-10-09 06:58:29 +00:00
|
|
|
|
GivenQueue(remoteEpisodes);
|
2014-10-27 05:51:50 +00:00
|
|
|
|
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
2013-10-09 06:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|