2012-02-07 06:08:07 +01:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-03-07 01:19:49 +01:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-02-19 03:19:38 +01:00
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
2013-02-19 03:19:38 +01:00
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 06:44:06 +01:00
|
|
|
|
public class AllowedDownloadSpecificationFixture : CoreTest
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
private AllowedDownloadSpecification spec;
|
|
|
|
|
private EpisodeParseResult parseResult;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
spec = Mocker.Resolve<AllowedDownloadSpecification>();
|
|
|
|
|
parseResult = new EpisodeParseResult();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<QualityAllowedByProfileSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<AcceptableSizeSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<UpgradeDiskSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
2013-03-07 01:19:49 +01:00
|
|
|
|
Mocker.GetMock<NotInQueueSpecification>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
2012-02-17 10:52:29 +01:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<RetentionSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
2012-08-25 21:31:17 +02:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<AllowedReleaseGroupSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
2012-09-19 17:13:26 +02:00
|
|
|
|
|
2012-09-20 17:37:40 +02:00
|
|
|
|
Mocker.GetMock<CustomStartDateSpecification>()
|
2012-09-19 17:13:26 +02:00
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
2013-01-16 02:36:02 +01:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<LanguageSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithProfileNotAllowed()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<QualityAllowedByProfileSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithNotAcceptableSize()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<AcceptableSizeSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithNoDiskUpgrade()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<UpgradeDiskSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithEpisodeAlreadyInQueue()
|
|
|
|
|
{
|
2013-03-07 01:19:49 +01:00
|
|
|
|
Mocker.GetMock<NotInQueueSpecification>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-17 10:52:29 +01:00
|
|
|
|
private void WithOverRetention()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<RetentionSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-20 17:37:40 +02:00
|
|
|
|
private void WithAiredBeforeCustomStartDateCutoff()
|
2012-09-19 17:13:26 +02:00
|
|
|
|
{
|
2012-09-20 17:37:40 +02:00
|
|
|
|
Mocker.GetMock<CustomStartDateSpecification>()
|
2012-09-19 17:13:26 +02:00
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 02:36:02 +01:00
|
|
|
|
private void WithLanguageNotWanted()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<LanguageSpecification>()
|
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_allowed_if_all_conditions_are_met()
|
|
|
|
|
{
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.None);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_profile_is_not_allowed()
|
|
|
|
|
{
|
|
|
|
|
WithProfileNotAllowed();
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.QualityNotWanted);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_size_is_not_allowed()
|
|
|
|
|
{
|
|
|
|
|
WithNotAcceptableSize();
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.Size);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_disk_is_not_upgrade()
|
|
|
|
|
{
|
|
|
|
|
WithNoDiskUpgrade();
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.ExistingQualityIsEqualOrBetter);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_episode_is_already_in_queue()
|
|
|
|
|
{
|
|
|
|
|
WithEpisodeAlreadyInQueue();
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.AlreadyInQueue);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-17 10:52:29 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_report_is_over_retention()
|
|
|
|
|
{
|
|
|
|
|
WithOverRetention();
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.Retention);
|
2012-02-17 10:52:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 17:13:26 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_episode_aired_before_cutoff()
|
|
|
|
|
{
|
2012-09-20 17:37:40 +02:00
|
|
|
|
WithAiredBeforeCustomStartDateCutoff();
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.AiredAfterCustomStartDate);
|
2012-09-19 17:13:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_none_of_conditions_are_met()
|
|
|
|
|
{
|
|
|
|
|
WithNoDiskUpgrade();
|
|
|
|
|
WithNotAcceptableSize();
|
|
|
|
|
WithProfileNotAllowed();
|
2012-02-17 10:52:29 +01:00
|
|
|
|
WithOverRetention();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.QualityNotWanted);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
2013-01-16 02:36:02 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_be_allowed_if_language_is_not_wanted()
|
|
|
|
|
{
|
|
|
|
|
WithLanguageNotWanted();
|
|
|
|
|
|
2013-03-06 21:30:53 +01:00
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.LanguageNotWanted);
|
2013-01-16 02:36:02 +01:00
|
|
|
|
}
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|