mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
cleaned up episode search
This commit is contained in:
@@ -13,7 +13,6 @@ using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -1,181 +1,53 @@
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using System.ComponentModel;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class AllowedDownloadSpecificationFixture : CoreTest
|
||||
{
|
||||
private AllowedDownloadSpecification spec;
|
||||
private EpisodeParseResult parseResult;
|
||||
|
||||
private Mock<IFetchableSpecification> pass1;
|
||||
private Mock<IFetchableSpecification> pass2;
|
||||
private Mock<IFetchableSpecification> pass3;
|
||||
|
||||
private Mock<IFetchableSpecification> fail1;
|
||||
private Mock<IFetchableSpecification> fail2;
|
||||
private Mock<IFetchableSpecification> fail3;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
spec = Mocker.Resolve<AllowedDownloadSpecification>();
|
||||
pass1 = new Mock<IFetchableSpecification>();
|
||||
pass2 = new Mock<IFetchableSpecification>();
|
||||
pass3 = new Mock<IFetchableSpecification>();
|
||||
|
||||
fail1 = new Mock<IFetchableSpecification>();
|
||||
fail2 = new Mock<IFetchableSpecification>();
|
||||
fail3 = new Mock<IFetchableSpecification>();
|
||||
|
||||
pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
|
||||
fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
|
||||
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<NotInQueueSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<RetentionSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<AllowedReleaseGroupSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<CustomStartDateSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<LanguageSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
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<NotInQueueSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void WithOverRetention()
|
||||
{
|
||||
Mocker.GetMock<RetentionSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
private void WithAiredBeforeCustomStartDateCutoff()
|
||||
{
|
||||
Mocker.GetMock<CustomStartDateSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
private void WithLanguageNotWanted()
|
||||
{
|
||||
Mocker.GetMock<LanguageSpecification>()
|
||||
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_allowed_if_all_conditions_are_met()
|
||||
public void should_call_all_specifications()
|
||||
{
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.None);
|
||||
throw new InvalidAsynchronousStateException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_profile_is_not_allowed()
|
||||
{
|
||||
WithProfileNotAllowed();
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.QualityNotWanted);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_size_is_not_allowed()
|
||||
{
|
||||
WithNotAcceptableSize();
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.Size);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_disk_is_not_upgrade()
|
||||
{
|
||||
WithNoDiskUpgrade();
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.ExistingQualityIsEqualOrBetter);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_episode_is_already_in_queue()
|
||||
{
|
||||
WithEpisodeAlreadyInQueue();
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.AlreadyInQueue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_report_is_over_retention()
|
||||
{
|
||||
WithOverRetention();
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.Retention);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_episode_aired_before_cutoff()
|
||||
{
|
||||
WithAiredBeforeCustomStartDateCutoff();
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.AiredAfterCustomStartDate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_none_of_conditions_are_met()
|
||||
{
|
||||
WithNoDiskUpgrade();
|
||||
WithNotAcceptableSize();
|
||||
WithProfileNotAllowed();
|
||||
WithOverRetention();
|
||||
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.QualityNotWanted);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_allowed_if_language_is_not_wanted()
|
||||
{
|
||||
WithLanguageNotWanted();
|
||||
|
||||
spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionReasons.LanguageNotWanted);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -12,7 +12,7 @@ using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -11,7 +11,7 @@ using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -12,7 +12,7 @@ using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -12,7 +12,7 @@ using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -13,7 +13,7 @@ using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
@@ -12,7 +12,7 @@ using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
Reference in New Issue
Block a user