mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-27 22:56:45 -04:00
Moved source code under src folder - massive change
This commit is contained in:
@@ -0,0 +1,380 @@
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class AcceptableSizeSpecificationFixture : CoreTest<AcceptableSizeSpecification>
|
||||
{
|
||||
private RemoteEpisode parseResultMulti;
|
||||
private RemoteEpisode parseResultSingle;
|
||||
private Series series30minutes;
|
||||
private Series series60minutes;
|
||||
private QualitySize qualityType;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
parseResultMulti = new RemoteEpisode
|
||||
{
|
||||
Release = new ReleaseInfo(),
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
|
||||
Episodes = new List<Episode> { new Episode(), new Episode() }
|
||||
};
|
||||
|
||||
parseResultSingle = new RemoteEpisode
|
||||
{
|
||||
Release = new ReleaseInfo(),
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
|
||||
Episodes = new List<Episode> { new Episode() }
|
||||
|
||||
};
|
||||
|
||||
series30minutes = Builder<Series>.CreateNew()
|
||||
.With(c => c.Runtime = 30)
|
||||
.Build();
|
||||
|
||||
series60minutes = Builder<Series>.CreateNew()
|
||||
.With(c => c.Runtime = 60)
|
||||
.Build();
|
||||
|
||||
qualityType = Builder<QualitySize>.CreateNew()
|
||||
.With(q => q.MinSize = 0)
|
||||
.With(q => q.MaxSize = 10)
|
||||
.With(q => q.QualityId = 1)
|
||||
.Build();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute()
|
||||
{
|
||||
parseResultSingle.Series = series30minutes;
|
||||
parseResultSingle.Release.Size = 184572800;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute()
|
||||
{
|
||||
parseResultSingle.Series = series60minutes;
|
||||
parseResultSingle.Release.Size = 368572800;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute()
|
||||
{
|
||||
parseResultSingle.Series = series30minutes;
|
||||
parseResultSingle.Release.Size = 1.Gigabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute()
|
||||
{
|
||||
parseResultSingle.Series = series60minutes;
|
||||
parseResultSingle.Release.Size = 1.Gigabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute()
|
||||
{
|
||||
parseResultMulti.Series = series30minutes;
|
||||
parseResultMulti.Release.Size = 184572800;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute()
|
||||
{
|
||||
parseResultMulti.Series = series60minutes;
|
||||
parseResultMulti.Release.Size = 368572800;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute()
|
||||
{
|
||||
parseResultMulti.Series = series30minutes;
|
||||
parseResultMulti.Release.Size = 1.Gigabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
|
||||
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute()
|
||||
{
|
||||
parseResultMulti.Series = series60minutes;
|
||||
parseResultMulti.Release.Size = 10.Gigabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
|
||||
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_single_episode_first_30_minute()
|
||||
{
|
||||
parseResultSingle.Series = series30minutes;
|
||||
parseResultSingle.Release.Size = 184572800;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_single_episode_first_60_minute()
|
||||
{
|
||||
parseResultSingle.Series = series60minutes;
|
||||
parseResultSingle.Release.Size = 368572800;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_false_single_episode_first_30_minute()
|
||||
{
|
||||
parseResultSingle.Series = series30minutes;
|
||||
parseResultSingle.Release.Size = 1.Gigabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_false_single_episode_first_60_minute()
|
||||
{
|
||||
|
||||
|
||||
parseResultSingle.Series = series60minutes;
|
||||
parseResultSingle.Release.Size = 10.Gigabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_unlimited_30_minute()
|
||||
{
|
||||
|
||||
|
||||
parseResultSingle.Series = series30minutes;
|
||||
parseResultSingle.Release.Size = 18457280000;
|
||||
qualityType.MaxSize = 0;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_true_unlimited_60_minute()
|
||||
{
|
||||
|
||||
|
||||
parseResultSingle.Series = series60minutes;
|
||||
parseResultSingle.Release.Size = 36857280000;
|
||||
qualityType.MaxSize = 0;
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsAcceptableSize_should_treat_daily_series_as_single_episode()
|
||||
{
|
||||
|
||||
parseResultSingle.Series = series60minutes;
|
||||
parseResultSingle.Series.SeriesType = SeriesTypes.Daily;
|
||||
|
||||
parseResultSingle.Release.Size = 300.Megabytes();
|
||||
|
||||
qualityType.MaxSize = (int)600.Megabytes();
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Setup(s => s.Get(1)).Returns(qualityType);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(
|
||||
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_RAWHD()
|
||||
{
|
||||
var parseResult = new RemoteEpisode
|
||||
{
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.RAWHD, false) },
|
||||
};
|
||||
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_always_return_false_if_unknow()
|
||||
{
|
||||
var parseResult = new RemoteEpisode
|
||||
{
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.Unknown, false) },
|
||||
};
|
||||
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeFalse();
|
||||
|
||||
|
||||
Mocker.GetMock<IQualitySizeService>().Verify(c=>c.Get(It.IsAny<int>()),Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CutoffSpecificationFixture : CoreTest<QualityUpgradableSpecification>
|
||||
{
|
||||
[Test]
|
||||
public void should_return_true_if_current_episode_is_less_than_cutoff()
|
||||
{
|
||||
Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.Bluray1080p },
|
||||
new QualityModel(Quality.DVD, true)).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_current_episode_is_equal_to_cutoff()
|
||||
{
|
||||
Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.HDTV720p },
|
||||
new QualityModel(Quality.HDTV720p, true)).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_current_episode_is_greater_than_cutoff()
|
||||
{
|
||||
Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.HDTV720p },
|
||||
new QualityModel(Quality.Bluray1080p, true)).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_new_episode_is_proper_but_existing_is_not()
|
||||
{
|
||||
Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.HDTV720p },
|
||||
new QualityModel(Quality.HDTV720p, false), new QualityModel(Quality.HDTV720p, true)).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_cutoff_is_met_and_quality_is_higher()
|
||||
{
|
||||
Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.HDTV720p },
|
||||
new QualityModel(Quality.HDTV720p, true), new QualityModel(Quality.Bluray1080p, true)).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class DownloadDecisionMakerFixture : CoreTest<DownloadDecisionMaker>
|
||||
{
|
||||
private List<ReleaseInfo> _reports;
|
||||
private RemoteEpisode _remoteEpisode;
|
||||
|
||||
private Mock<IDecisionEngineSpecification> _pass1;
|
||||
private Mock<IDecisionEngineSpecification> _pass2;
|
||||
private Mock<IDecisionEngineSpecification> _pass3;
|
||||
|
||||
private Mock<IDecisionEngineSpecification> _fail1;
|
||||
private Mock<IDecisionEngineSpecification> _fail2;
|
||||
private Mock<IDecisionEngineSpecification> _fail3;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_pass1 = new Mock<IDecisionEngineSpecification>();
|
||||
_pass2 = new Mock<IDecisionEngineSpecification>();
|
||||
_pass3 = new Mock<IDecisionEngineSpecification>();
|
||||
|
||||
_fail1 = new Mock<IDecisionEngineSpecification>();
|
||||
_fail2 = new Mock<IDecisionEngineSpecification>();
|
||||
_fail3 = new Mock<IDecisionEngineSpecification>();
|
||||
|
||||
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(true);
|
||||
_pass1.Setup(c => c.RejectionReason).Returns("_pass1");
|
||||
|
||||
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(true);
|
||||
_pass2.Setup(c => c.RejectionReason).Returns("_pass2");
|
||||
|
||||
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(true);
|
||||
_pass3.Setup(c => c.RejectionReason).Returns("_pass3");
|
||||
|
||||
|
||||
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(false);
|
||||
_fail1.Setup(c => c.RejectionReason).Returns("_fail1");
|
||||
|
||||
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(false);
|
||||
_fail2.Setup(c => c.RejectionReason).Returns("_fail2");
|
||||
|
||||
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(false);
|
||||
_fail3.Setup(c => c.RejectionReason).Returns("_fail3");
|
||||
|
||||
_reports = new List<ReleaseInfo> { new ReleaseInfo { Title = "The.Office.S03E115.DVDRip.XviD-OSiTV" } };
|
||||
_remoteEpisode = new RemoteEpisode { Series = new Series() };
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
|
||||
.Returns(_remoteEpisode);
|
||||
}
|
||||
|
||||
private void GivenSpecifications(params Mock<IDecisionEngineSpecification>[] mocks)
|
||||
{
|
||||
Mocker.SetConstant<IEnumerable<IRejectWithReason>>(mocks.Select(c => c.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_all_specifications()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
Subject.GetRssDecision(_reports).ToList();
|
||||
|
||||
_fail1.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
_fail2.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
_fail3.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_single_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_fail1);
|
||||
|
||||
var result = Subject.GetRssDecision(_reports);
|
||||
|
||||
result.Single().Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_one_of_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetRssDecision(_reports);
|
||||
|
||||
result.Single().Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_pass_if_all_specs_pass()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetRssDecision(_reports);
|
||||
|
||||
result.Single().Approved.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
var result = Subject.GetRssDecision(_reports);
|
||||
result.Single().Rejections.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_attempt_to_map_episode_if_not_parsable()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
_reports[0].Title = "Not parsable";
|
||||
|
||||
var results = Subject.GetRssDecision(_reports).ToList();
|
||||
|
||||
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Never());
|
||||
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
|
||||
results.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test] public void should_not_attempt_to_map_episode_series_title_is_blank()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
_reports[0].Title = "1937 - Snow White and the Seven Dwarves";
|
||||
|
||||
var results = Subject.GetRssDecision(_reports).ToList();
|
||||
|
||||
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Never());
|
||||
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
|
||||
results.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_attempt_to_make_decision_if_series_is_unknown()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
_remoteEpisode.Series = null;
|
||||
|
||||
Subject.GetRssDecision(_reports);
|
||||
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void broken_report_shouldnt_blowup_the_process()
|
||||
{
|
||||
GivenSpecifications(_pass1);
|
||||
|
||||
Mocker.GetMock<IParsingService>().Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
|
||||
.Throws<TestException>();
|
||||
|
||||
_reports = new List<ReleaseInfo>
|
||||
{
|
||||
new ReleaseInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"},
|
||||
new ReleaseInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"},
|
||||
new ReleaseInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"}
|
||||
};
|
||||
|
||||
Subject.GetRssDecision(_reports);
|
||||
|
||||
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Exactly(_reports.Count));
|
||||
|
||||
ExceptionVerification.ExpectedErrors(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_unknown_series_rejection_if_series_is_unknown()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
_remoteEpisode.Series = null;
|
||||
|
||||
var result = Subject.GetRssDecision(_reports);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class LanguageSpecificationFixture : CoreTest
|
||||
{
|
||||
private RemoteEpisode parseResult;
|
||||
|
||||
private void WithEnglishRelease()
|
||||
{
|
||||
parseResult = new RemoteEpisode
|
||||
{
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
Language = Language.English
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void WithGermanRelease()
|
||||
{
|
||||
parseResult = new RemoteEpisode
|
||||
{
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
Language = Language.German
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_language_is_english()
|
||||
{
|
||||
WithEnglishRelease();
|
||||
|
||||
Mocker.Resolve<LanguageSpecification>().IsSatisfiedBy(parseResult, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_language_is_german()
|
||||
{
|
||||
WithGermanRelease();
|
||||
|
||||
Mocker.Resolve<LanguageSpecification>().IsSatisfiedBy(parseResult, null).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class MonitoredEpisodeSpecificationFixture : CoreTest<MonitoredEpisodeSpecification>
|
||||
{
|
||||
private MonitoredEpisodeSpecification _monitoredEpisodeSpecification;
|
||||
|
||||
private RemoteEpisode _parseResultMulti;
|
||||
private RemoteEpisode _parseResultSingle;
|
||||
private Series _fakeSeries;
|
||||
private Episode _firstEpisode;
|
||||
private Episode _secondEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_monitoredEpisodeSpecification = Mocker.Resolve<MonitoredEpisodeSpecification>();
|
||||
|
||||
_fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(c => c.Monitored = true)
|
||||
.Build();
|
||||
|
||||
_firstEpisode = new Episode { Monitored = true };
|
||||
_secondEpisode = new Episode { Monitored = true };
|
||||
|
||||
|
||||
var singleEpisodeList = new List<Episode> { _firstEpisode };
|
||||
var doubleEpisodeList = new List<Episode> { _firstEpisode, _secondEpisode };
|
||||
|
||||
_parseResultMulti = new RemoteEpisode
|
||||
{
|
||||
Series = _fakeSeries,
|
||||
Episodes = doubleEpisodeList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteEpisode
|
||||
{
|
||||
Series = _fakeSeries,
|
||||
Episodes = singleEpisodeList
|
||||
};
|
||||
}
|
||||
|
||||
private void WithFirstEpisodeUnmonitored()
|
||||
{
|
||||
_firstEpisode.Monitored = false;
|
||||
}
|
||||
|
||||
private void WithSecondEpisodeUnmonitored()
|
||||
{
|
||||
_secondEpisode.Monitored = false;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void setup_should_return_monitored_episode_should_return_true()
|
||||
{
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void not_monitored_series_should_be_skipped()
|
||||
{
|
||||
_fakeSeries.Monitored = false;
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void only_episode_not_monitored_should_return_false()
|
||||
{
|
||||
WithFirstEpisodeUnmonitored();
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void both_episodes_not_monitored_should_return_false()
|
||||
{
|
||||
WithFirstEpisodeUnmonitored();
|
||||
WithSecondEpisodeUnmonitored();
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void only_first_episode_not_monitored_should_return_monitored()
|
||||
{
|
||||
WithFirstEpisodeUnmonitored();
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void only_second_episode_not_monitored_should_return_monitored()
|
||||
{
|
||||
WithSecondEpisodeUnmonitored();
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_it_is_a_search()
|
||||
{
|
||||
_fakeSeries.Monitored = false;
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, new SeasonSearchCriteria()).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotRestrictedReleaseSpecificationFixture : CoreTest<NotRestrictedReleaseSpecification>
|
||||
{
|
||||
private RemoteEpisode _parseResult;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_parseResult = new RemoteEpisode
|
||||
{
|
||||
Release = new ReleaseInfo
|
||||
{
|
||||
Title = "Dexter.S08E01.EDITED.WEBRip.x264-KYR"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_true_when_restrictions_are_empty()
|
||||
{
|
||||
Subject.IsSatisfiedBy(_parseResult, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[TestCase("KYR")]
|
||||
[TestCase("EDITED")]
|
||||
[TestCase("edited")]
|
||||
[TestCase("2HD\nKYR")]
|
||||
[TestCase("2HD\nkyr")]
|
||||
public void should_be_false_when_nzb_contains_a_restricted_term(string restrictions)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.ReleaseRestrictions).Returns(restrictions);
|
||||
Subject.IsSatisfiedBy(_parseResult, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[TestCase("NotReal")]
|
||||
[TestCase("LoL")]
|
||||
[TestCase("Hello\nWorld")]
|
||||
public void should_be_true_when_nzb_does_not_contain_a_restricted_term(string restrictions)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.ReleaseRestrictions).Returns(restrictions);
|
||||
Subject.IsSatisfiedBy(_parseResult, null).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Marr.Data;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class QualityAllowedByProfileSpecificationFixture : CoreTest<QualityAllowedByProfileSpecification>
|
||||
{
|
||||
private RemoteEpisode remoteEpisode;
|
||||
|
||||
public static object[] AllowedTestCases =
|
||||
{
|
||||
new object[] { Quality.DVD },
|
||||
new object[] { Quality.HDTV720p },
|
||||
new object[] { Quality.Bluray1080p }
|
||||
};
|
||||
|
||||
public static object[] DeniedTestCases =
|
||||
{
|
||||
new object[] { Quality.SDTV },
|
||||
new object[] { Quality.WEBDL720p },
|
||||
new object[] { Quality.Bluray720p }
|
||||
};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(c => c.QualityProfile = (LazyLoaded<QualityProfile>)new QualityProfile { Cutoff = Quality.Bluray1080p })
|
||||
.Build();
|
||||
|
||||
remoteEpisode = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
};
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("AllowedTestCases")]
|
||||
public void should_allow_if_quality_is_defined_in_profile(Quality qualityType)
|
||||
{
|
||||
remoteEpisode.ParsedEpisodeInfo.Quality.Quality = qualityType;
|
||||
remoteEpisode.Series.QualityProfile.Value.Allowed = new List<Quality> { Quality.DVD, Quality.HDTV720p, Quality.Bluray1080p };
|
||||
|
||||
Subject.IsSatisfiedBy(remoteEpisode, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("DeniedTestCases")]
|
||||
public void should_not_allow_if_quality_is_not_defined_in_profile(Quality qualityType)
|
||||
{
|
||||
remoteEpisode.ParsedEpisodeInfo.Quality.Quality = qualityType;
|
||||
remoteEpisode.Series.QualityProfile.Value.Allowed = new List<Quality> { Quality.DVD, Quality.HDTV720p, Quality.Bluray1080p };
|
||||
|
||||
Subject.IsSatisfiedBy(remoteEpisode, null).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class QualityUpgradeSpecificationFixture : CoreTest<QualityUpgradableSpecification>
|
||||
{
|
||||
public static object[] IsUpgradeTestCases =
|
||||
{
|
||||
new object[] { Quality.SDTV, false, Quality.SDTV, true, Quality.SDTV, true },
|
||||
new object[] { Quality.WEBDL720p, false, Quality.WEBDL720p, true, Quality.WEBDL720p, true },
|
||||
new object[] { Quality.SDTV, false, Quality.SDTV, false, Quality.SDTV, false },
|
||||
new object[] { Quality.WEBDL720p, false, Quality.HDTV720p, true, Quality.Bluray720p, false },
|
||||
new object[] { Quality.WEBDL720p, false, Quality.HDTV720p, true, Quality.WEBDL720p, false },
|
||||
new object[] { Quality.WEBDL720p, false, Quality.WEBDL720p, false, Quality.WEBDL720p, false },
|
||||
new object[] { Quality.SDTV, false, Quality.SDTV, true, Quality.SDTV, true },
|
||||
new object[] { Quality.WEBDL1080p, false, Quality.WEBDL1080p, false, Quality.WEBDL1080p, false }
|
||||
};
|
||||
|
||||
private void GivenAutoDownloadPropers(bool autoDownloadPropers)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.AutoDownloadPropers)
|
||||
.Returns(autoDownloadPropers);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("IsUpgradeTestCases")]
|
||||
public void IsUpgradeTest(Quality current, bool currentProper, Quality newQuality, bool newProper, Quality cutoff, bool expected)
|
||||
{
|
||||
GivenAutoDownloadPropers(true);
|
||||
|
||||
Subject.IsUpgradable(new QualityModel(current, currentProper), new QualityModel(newQuality, newProper))
|
||||
.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_proper_and_autoDownloadPropers_is_false()
|
||||
{
|
||||
GivenAutoDownloadPropers(false);
|
||||
|
||||
Subject.IsUpgradable(new QualityModel(Quality.DVD, true),
|
||||
new QualityModel(Quality.DVD, false)).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class RetentionSpecificationFixture : CoreTest<RetentionSpecification>
|
||||
{
|
||||
|
||||
private RemoteEpisode parseResult;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
parseResult = new RemoteEpisode
|
||||
{
|
||||
Release = new ReleaseInfo
|
||||
{
|
||||
PublishDate = DateTime.Now.AddDays(-100)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void WithUnlimitedRetention()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(0);
|
||||
}
|
||||
|
||||
private void WithLongRetention()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(1000);
|
||||
}
|
||||
|
||||
private void WithShortRetention()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(10);
|
||||
}
|
||||
|
||||
private void WithEqualRetention()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.Retention).Returns(100);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void unlimited_retention_should_return_true()
|
||||
{
|
||||
WithUnlimitedRetention();
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void longer_retention_should_return_true()
|
||||
{
|
||||
WithLongRetention();
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void equal_retention_should_return_true()
|
||||
{
|
||||
WithEqualRetention();
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void shorter_retention_should_return_false()
|
||||
{
|
||||
WithShortRetention();
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void zeroDay_report_should_return_true()
|
||||
{
|
||||
WithUnlimitedRetention();
|
||||
Subject.IsSatisfiedBy(parseResult, null).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class ProperSpecificationFixture : CoreTest<ProperSpecification>
|
||||
{
|
||||
private RemoteEpisode _parseResultMulti;
|
||||
private RemoteEpisode _parseResultSingle;
|
||||
private EpisodeFile _firstFile;
|
||||
private EpisodeFile _secondFile;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.Resolve<QualityUpgradableSpecification>();
|
||||
|
||||
_firstFile = new EpisodeFile { Quality = new QualityModel(Quality.Bluray1080p, false), DateAdded = DateTime.Now };
|
||||
_secondFile = new EpisodeFile { Quality = new QualityModel(Quality.Bluray1080p, false), DateAdded = DateTime.Now };
|
||||
|
||||
var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = _firstFile, EpisodeFileId = 1 }, new Episode { EpisodeFile = null } };
|
||||
var doubleEpisodeList = new List<Episode> { new Episode { EpisodeFile = _firstFile, EpisodeFileId = 1 }, new Episode { EpisodeFile = _secondFile, EpisodeFileId = 1 }, new Episode { EpisodeFile = null } };
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p })
|
||||
.Build();
|
||||
|
||||
_parseResultMulti = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
Episodes = doubleEpisodeList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
Episodes = singleEpisodeList
|
||||
};
|
||||
}
|
||||
|
||||
private void WithFirstFileUpgradable()
|
||||
{
|
||||
_firstFile.Quality = new QualityModel(Quality.SDTV);
|
||||
}
|
||||
|
||||
private void GivenAutoDownloadPropers()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.AutoDownloadPropers)
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_episodeFile_was_added_more_than_7_days_ago()
|
||||
{
|
||||
_firstFile.Quality.Quality = Quality.DVD;
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today.AddDays(-30);
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_first_episodeFile_was_added_more_than_7_days_ago()
|
||||
{
|
||||
_firstFile.Quality.Quality = Quality.DVD;
|
||||
_secondFile.Quality.Quality = Quality.DVD;
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today.AddDays(-30);
|
||||
Subject.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_second_episodeFile_was_added_more_than_7_days_ago()
|
||||
{
|
||||
_firstFile.Quality.Quality = Quality.DVD;
|
||||
_secondFile.Quality.Quality = Quality.DVD;
|
||||
|
||||
_secondFile.DateAdded = DateTime.Today.AddDays(-30);
|
||||
Subject.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_episodeFile_was_added_more_than_7_days_ago_but_proper_is_for_better_quality()
|
||||
{
|
||||
WithFirstFileUpgradable();
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today.AddDays(-30);
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_episodeFile_was_added_more_than_7_days_ago_but_is_for_search()
|
||||
{
|
||||
WithFirstFileUpgradable();
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today.AddDays(-30);
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, new SingleEpisodeSearchCriteria()).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_proper_but_auto_download_propers_is_false()
|
||||
{
|
||||
_firstFile.Quality.Quality = Quality.DVD;
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today;
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_episodeFile_was_added_today()
|
||||
{
|
||||
GivenAutoDownloadPropers();
|
||||
|
||||
_firstFile.Quality.Quality = Quality.DVD;
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today;
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class UpgradeDiskSpecificationFixture : CoreTest<UpgradeDiskSpecification>
|
||||
{
|
||||
private UpgradeDiskSpecification _upgradeDisk;
|
||||
|
||||
private RemoteEpisode _parseResultMulti;
|
||||
private RemoteEpisode _parseResultSingle;
|
||||
private EpisodeFile _firstFile;
|
||||
private EpisodeFile _secondFile;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.Resolve<QualityUpgradableSpecification>();
|
||||
_upgradeDisk = Mocker.Resolve<UpgradeDiskSpecification>();
|
||||
|
||||
_firstFile = new EpisodeFile { Quality = new QualityModel(Quality.Bluray1080p, true), DateAdded = DateTime.Now };
|
||||
_secondFile = new EpisodeFile { Quality = new QualityModel(Quality.Bluray1080p, true), DateAdded = DateTime.Now };
|
||||
|
||||
var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = _firstFile, EpisodeFileId = 1 }, new Episode { EpisodeFile = null } };
|
||||
var doubleEpisodeList = new List<Episode> { new Episode { EpisodeFile = _firstFile, EpisodeFileId = 1 }, new Episode { EpisodeFile = _secondFile, EpisodeFileId = 1 }, new Episode { EpisodeFile = null } };
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p })
|
||||
.Build();
|
||||
|
||||
_parseResultMulti = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
Episodes = doubleEpisodeList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
Episodes = singleEpisodeList
|
||||
};
|
||||
}
|
||||
|
||||
private void WithFirstFileUpgradable()
|
||||
{
|
||||
_firstFile.Quality = new QualityModel(Quality.SDTV);
|
||||
}
|
||||
|
||||
private void WithSecondFileUpgradable()
|
||||
{
|
||||
_secondFile.Quality = new QualityModel(Quality.SDTV);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_episode_has_no_existing_file()
|
||||
{
|
||||
_parseResultSingle.Episodes.ForEach(c => c.EpisodeFileId = 0);
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_single_episode_doesnt_exist_on_disk()
|
||||
{
|
||||
_parseResultSingle.Episodes = new List<Episode>();
|
||||
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_upgradable_if_only_episode_is_upgradable()
|
||||
{
|
||||
WithFirstFileUpgradable();
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_upgradable_if_both_episodes_are_upgradable()
|
||||
{
|
||||
WithFirstFileUpgradable();
|
||||
WithSecondFileUpgradable();
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultMulti, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_both_episodes_are_not_upgradable()
|
||||
{
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
|
||||
{
|
||||
WithFirstFileUpgradable();
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
|
||||
{
|
||||
WithSecondFileUpgradable();
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_upgradable_if_qualities_are_the_same()
|
||||
{
|
||||
_firstFile.Quality = new QualityModel(Quality.WEBDL1080p);
|
||||
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, false);
|
||||
_upgradeDisk.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpgradeHistorySpecificationFixture : CoreTest<UpgradeHistorySpecification>
|
||||
{
|
||||
private UpgradeHistorySpecification _upgradeHistory;
|
||||
|
||||
private RemoteEpisode _parseResultMulti;
|
||||
private RemoteEpisode _parseResultSingle;
|
||||
private QualityModel _upgradableQuality;
|
||||
private QualityModel _notupgradableQuality;
|
||||
private Series _fakeSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.Resolve<QualityUpgradableSpecification>();
|
||||
_upgradeHistory = Mocker.Resolve<UpgradeHistorySpecification>();
|
||||
|
||||
var singleEpisodeList = new List<Episode> { new Episode { Id = 1, SeasonNumber = 12, EpisodeNumber = 3 } };
|
||||
var doubleEpisodeList = new List<Episode> {
|
||||
new Episode {Id = 1, SeasonNumber = 12, EpisodeNumber = 3 },
|
||||
new Episode {Id = 2, SeasonNumber = 12, EpisodeNumber = 4 },
|
||||
new Episode {Id = 3, SeasonNumber = 12, EpisodeNumber = 5 }
|
||||
};
|
||||
|
||||
_fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(c => c.QualityProfile = new QualityProfile { Cutoff = Quality.Bluray1080p })
|
||||
.Build();
|
||||
|
||||
_parseResultMulti = new RemoteEpisode
|
||||
{
|
||||
Series = _fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
Episodes = doubleEpisodeList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteEpisode
|
||||
{
|
||||
Series = _fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, true) },
|
||||
Episodes = singleEpisodeList
|
||||
};
|
||||
|
||||
_upgradableQuality = new QualityModel(Quality.SDTV, false);
|
||||
_notupgradableQuality = new QualityModel(Quality.HDTV1080p, true);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_notupgradableQuality);
|
||||
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_notupgradableQuality);
|
||||
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(3)).Returns<QualityModel>(null);
|
||||
}
|
||||
|
||||
private void WithFirstReportUpgradable()
|
||||
{
|
||||
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
|
||||
}
|
||||
|
||||
private void WithSecondReportUpgradable()
|
||||
{
|
||||
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_upgradableQuality);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_be_upgradable_if_only_episode_is_upgradable()
|
||||
{
|
||||
WithFirstReportUpgradable();
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_upgradable_if_both_episodes_are_upgradable()
|
||||
{
|
||||
WithFirstReportUpgradable();
|
||||
WithSecondReportUpgradable();
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
|
||||
{
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
|
||||
{
|
||||
WithFirstReportUpgradable();
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
|
||||
{
|
||||
WithSecondReportUpgradable();
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing()
|
||||
{
|
||||
_fakeSeries.QualityProfile = new QualityProfile { Cutoff = Quality.WEBDL1080p };
|
||||
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, false);
|
||||
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, false);
|
||||
|
||||
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality);
|
||||
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_it_is_a_search()
|
||||
{
|
||||
_upgradeHistory.IsSatisfiedBy(_parseResultMulti, new SeasonSearchCriteria()).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user