2012-02-07 08:08:07 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Providers.DecisionEngine;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class AllowedDownloadSpecificationFixture : CoreTest
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
Mocker.GetMock<AlreadyInQueueSpecification>()
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(false);
|
2012-02-17 12:52:29 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<RetentionSpecification>()
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(true);
|
2012-08-25 22:31:17 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<AllowedReleaseGroupSpecification>()
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(true);
|
2012-09-19 18:13:26 +03:00
|
|
|
|
2012-09-20 18:37:40 +03:00
|
|
|
Mocker.GetMock<CustomStartDateSpecification>()
|
2012-09-19 18:13:26 +03:00
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(true);
|
2012-02-07 08:08:07 +03: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()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<AlreadyInQueueSpecification>()
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(true);
|
|
|
|
}
|
|
|
|
|
2012-02-17 12:52:29 +03:00
|
|
|
private void WithOverRetention()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<RetentionSpecification>()
|
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(false);
|
|
|
|
}
|
|
|
|
|
2012-09-20 18:37:40 +03:00
|
|
|
private void WithAiredBeforeCustomStartDateCutoff()
|
2012-09-19 18:13:26 +03:00
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
Mocker.GetMock<CustomStartDateSpecification>()
|
2012-09-19 18:13:26 +03:00
|
|
|
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
|
|
|
.Returns(false);
|
|
|
|
}
|
|
|
|
|
2012-02-07 08:08:07 +03:00
|
|
|
[Test]
|
|
|
|
public void should_be_allowed_if_all_conditions_are_met()
|
|
|
|
{
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.None);
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_profile_is_not_allowed()
|
|
|
|
{
|
|
|
|
WithProfileNotAllowed();
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.QualityNotWanted);
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_size_is_not_allowed()
|
|
|
|
{
|
|
|
|
WithNotAcceptableSize();
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.Size);
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_disk_is_not_upgrade()
|
|
|
|
{
|
|
|
|
WithNoDiskUpgrade();
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.ExistingQualityIsEqualOrBetter);
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_episode_is_already_in_queue()
|
|
|
|
{
|
|
|
|
WithEpisodeAlreadyInQueue();
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.AlreadyInQueue);
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
2012-02-17 12:52:29 +03:00
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_report_is_over_retention()
|
|
|
|
{
|
|
|
|
WithOverRetention();
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.Retention);
|
2012-02-17 12:52:29 +03:00
|
|
|
}
|
|
|
|
|
2012-09-19 18:13:26 +03:00
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_episode_aired_before_cutoff()
|
|
|
|
{
|
2012-09-20 18:37:40 +03:00
|
|
|
WithAiredBeforeCustomStartDateCutoff();
|
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.AiredAfterCustomStartDate);
|
2012-09-19 18:13:26 +03:00
|
|
|
}
|
|
|
|
|
2012-02-07 08:08:07 +03:00
|
|
|
[Test]
|
|
|
|
public void should_not_be_allowed_if_none_of_conditions_are_met()
|
|
|
|
{
|
|
|
|
WithNoDiskUpgrade();
|
|
|
|
WithNotAcceptableSize();
|
|
|
|
WithProfileNotAllowed();
|
2012-02-17 12:52:29 +03:00
|
|
|
WithOverRetention();
|
2012-02-07 08:08:07 +03:00
|
|
|
|
2012-04-20 09:42:13 +03:00
|
|
|
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.QualityNotWanted);
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|