New: Rewrite of download decision engine.

This commit is contained in:
kay.one
2012-02-06 21:08:07 -08:00
parent a168bdfa00
commit 5717b7f596
60 changed files with 2013 additions and 1745 deletions
@@ -0,0 +1,391 @@
// 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 AcceptableSizeSpecificationFixture : CoreTest
{
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;
private Series series30minutes;
private Series series60minutes;
private QualityType qualityType;
[SetUp]
public void Setup()
{
parseResultMulti = new EpisodeParseResult
{
SeriesTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.SDTV, true),
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date
};
parseResultSingle = new EpisodeParseResult
{
SeriesTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.SDTV, true),
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date
};
series30minutes = Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(d => d.CleanTitle = parseResultMulti.CleanTitle)
.With(c => c.Runtime = 30)
.Build();
series60minutes = Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(d => d.CleanTitle = parseResultMulti.CleanTitle)
.With(c => c.Runtime = 60)
.Build();
qualityType = Builder<QualityType>.CreateNew()
.With(q => q.MinSize = 0)
.With(q => q.MaxSize = 10)
.With(q => q.QualityTypeId = 1)
.Build();
}
[Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute()
{
WithStrictMocker();
parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 184572800;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute()
{
WithStrictMocker();
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 368572800;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute()
{
WithStrictMocker();
parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 1.Gigabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute()
{
WithStrictMocker();
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 1.Gigabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute()
{
WithStrictMocker();
parseResultMulti.Series = series30minutes;
parseResultMulti.Size = 184572800;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultMulti);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute()
{
WithStrictMocker();
parseResultMulti.Series = series60minutes;
parseResultMulti.Size = 368572800;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultMulti);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute()
{
WithStrictMocker();
parseResultMulti.Series = series30minutes;
parseResultMulti.Size = 1.Gigabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultMulti);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute()
{
WithStrictMocker();
parseResultMulti.Series = series60minutes;
parseResultMulti.Size = 10.Gigabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultMulti);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_true_single_episode_first_30_minute()
{
WithStrictMocker();
parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 184572800;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_true_single_episode_first_60_minute()
{
WithStrictMocker();
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 368572800;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_false_single_episode_first_30_minute()
{
WithStrictMocker();
parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 1.Gigabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_false_single_episode_first_60_minute()
{
WithStrictMocker();
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 10.Gigabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_true_unlimited_30_minute()
{
WithStrictMocker();
parseResultSingle.Series = series30minutes;
parseResultSingle.Size = 18457280000;
qualityType.MaxSize = 0;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_true_unlimited_60_minute()
{
WithStrictMocker();
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 36857280000;
qualityType.MaxSize = 0;
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_should_treat_daily_series_as_single_episode()
{
parseResultSingle.Series = series60minutes;
parseResultSingle.Size = 300.Megabytes();
parseResultSingle.AirDate = DateTime.Today;
parseResultSingle.EpisodeNumbers = null;
qualityType.MaxSize = (int)600.Megabytes();
Mocker.GetMock<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
Mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = Mocker.Resolve<AcceptableSizeSpecification>().IsSatisfiedBy(parseResultSingle);
//Assert
result.Should().BeTrue();
}
}
}
@@ -0,0 +1,121 @@
// 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);
}
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);
}
[Test]
public void should_be_allowed_if_all_conditions_are_met()
{
spec.IsSatisfiedBy(parseResult).Should().BeTrue();
}
[Test]
public void should_not_be_allowed_if_profile_is_not_allowed()
{
WithProfileNotAllowed();
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
}
[Test]
public void should_not_be_allowed_if_size_is_not_allowed()
{
WithNotAcceptableSize();
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
}
[Test]
public void should_not_be_allowed_if_disk_is_not_upgrade()
{
WithNoDiskUpgrade();
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
}
[Test]
public void should_not_be_allowed_if_episode_is_already_in_queue()
{
WithEpisodeAlreadyInQueue();
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
}
[Test]
public void should_not_be_allowed_if_none_of_conditions_are_met()
{
WithNoDiskUpgrade();
WithNotAcceptableSize();
WithProfileNotAllowed();
spec.IsSatisfiedBy(parseResult).Should().BeFalse();
}
}
}
@@ -0,0 +1,138 @@
// 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.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class MonitoredEpisodeSpecificationFixture : CoreTest
{
private MonitoredEpisodeSpecification monitoredEpisodeSpecification;
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult 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();
parseResultMulti = new EpisodeParseResult
{
SeriesTitle = "Title",
Series = fakeSeries,
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
};
parseResultSingle = new EpisodeParseResult
{
SeriesTitle = "Title",
Series = fakeSeries,
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
};
firstEpisode = new Episode { Ignored = false };
secondEpisode = new Episode { Ignored = false };
var singleEpisodeList = new List<Episode> { firstEpisode };
var doubleEpisodeList = new List<Episode> { firstEpisode, secondEpisode };
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultSingle)).Returns(singleEpisodeList);
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultMulti)).Returns(doubleEpisodeList);
Mocker.GetMock<SeriesProvider>().Setup(c => c.FindSeries(parseResultMulti.CleanTitle)).Returns(fakeSeries);
Mocker.GetMock<SeriesProvider>().Setup(c => c.FindSeries(parseResultSingle.CleanTitle)).Returns(fakeSeries);
}
private void WithFirstEpisodeIgnored()
{
firstEpisode.Ignored = true;
}
private void WithSecondEpisodeIgnored()
{
secondEpisode.Ignored = true;
}
[Test]
public void setup_should_return_monitored_episode_should_return_true()
{
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void not_monitored_series_should_be_skipped()
{
fakeSeries.Monitored = false;
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void not_in_db_should_be_skipped()
{
Mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns<Series>(null);
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void only_episode_ignored_should_return_false()
{
WithFirstEpisodeIgnored();
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
}
[Test]
public void both_episodes_ignored_should_return_false()
{
WithFirstEpisodeIgnored();
WithSecondEpisodeIgnored();
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void only_first_episode_ignored_should_return_monitored()
{
WithFirstEpisodeIgnored();
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void only_second_episode_ignored_should_return_monitored()
{
WithSecondEpisodeIgnored();
monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
}
}
@@ -0,0 +1,69 @@
// ReSharper disable RedundantUsingDirective
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model;
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 QualityAllowedByProfileSpecificationFixtrue : CoreTest
{
private QualityAllowedByProfileSpecification _qualityAllowedByProfile;
private EpisodeParseResult parseResult;
[SetUp]
public void Setup()
{
_qualityAllowedByProfile = Mocker.Resolve<QualityAllowedByProfileSpecification>();
var fakeSeries = Builder<Series>.CreateNew()
.With(c => c.QualityProfile = new QualityProfile { Cutoff = QualityTypes.Bluray1080p })
.Build();
parseResult = new EpisodeParseResult
{
Series = fakeSeries,
Quality = new Quality(QualityTypes.DVD, true),
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
};
}
[TestCase(QualityTypes.DVD)]
[TestCase(QualityTypes.HDTV)]
[TestCase(QualityTypes.Bluray1080p)]
public void should_allow_if_quality_is_defined_in_profile(QualityTypes qualityType)
{
parseResult.Quality.QualityType = qualityType;
parseResult.Series.QualityProfile.Allowed = new List<QualityTypes> { QualityTypes.DVD, QualityTypes.HDTV, QualityTypes.Bluray1080p };
_qualityAllowedByProfile.IsSatisfiedBy(parseResult).Should().BeTrue();
}
[TestCase(QualityTypes.SDTV)]
[TestCase(QualityTypes.WEBDL)]
[TestCase(QualityTypes.Bluray720p)]
public void should_not_allow_if_quality_is_not_defined_in_profile(QualityTypes qualityType)
{
parseResult.Quality.QualityType = qualityType;
parseResult.Series.QualityProfile.Allowed = new List<QualityTypes> { QualityTypes.DVD, QualityTypes.HDTV, QualityTypes.Bluray1080p };
_qualityAllowedByProfile.IsSatisfiedBy(parseResult).Should().BeFalse();
}
}
}
@@ -0,0 +1,30 @@
// ReSharper disable RedundantUsingDirective
using System.Linq;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.DecisionEngine;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class QualityUpgradeSpecificationFixture : CoreTest
{
[TestCase(QualityTypes.SDTV, false, QualityTypes.SDTV, true, QualityTypes.SDTV, Result = true)]
[TestCase(QualityTypes.WEBDL, false, QualityTypes.WEBDL, true, QualityTypes.WEBDL, Result = true)]
[TestCase(QualityTypes.SDTV, false, QualityTypes.SDTV, false, QualityTypes.SDTV, Result = false)]
[TestCase(QualityTypes.SDTV, false, QualityTypes.DVD, true, QualityTypes.SDTV, Result = false)]
[TestCase(QualityTypes.WEBDL, false, QualityTypes.HDTV, true, QualityTypes.Bluray720p, Result = false)]
[TestCase(QualityTypes.WEBDL, false, QualityTypes.HDTV, true, QualityTypes.WEBDL, Result = false)]
[TestCase(QualityTypes.WEBDL, false, QualityTypes.WEBDL, false, QualityTypes.WEBDL, Result = false)]
[TestCase(QualityTypes.SDTV, false, QualityTypes.SDTV, true, QualityTypes.SDTV, Result = true)]
public bool IsUpgradeTest(QualityTypes current, bool currentProper, QualityTypes newQuality, bool newProper, QualityTypes cutoff)
{
return new QualityUpgradeSpecification().IsSatisfiedBy(new Quality(current, currentProper), new Quality(newQuality, newProper), cutoff);
}
}
}
@@ -0,0 +1,118 @@
// ReSharper disable RedundantUsingDirective
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
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 UpgradeDiskSpecificationFixtrue : CoreTest
{
private UpgradeDiskSpecification _upgradeDisk;
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;
private EpisodeFile firstFile;
private EpisodeFile secondFile;
[SetUp]
public void Setup()
{
Mocker.Resolve<QualityUpgradeSpecification>();
_upgradeDisk = Mocker.Resolve<UpgradeDiskSpecification>();
var fakeSeries = Builder<Series>.CreateNew()
.With(c => c.QualityProfile = new QualityProfile { Cutoff = QualityTypes.Bluray1080p })
.Build();
parseResultMulti = new EpisodeParseResult
{
Series = fakeSeries,
Quality = new Quality(QualityTypes.DVD, true),
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
};
parseResultSingle = new EpisodeParseResult
{
Series = fakeSeries,
Quality = new Quality(QualityTypes.DVD, true),
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
};
firstFile = new EpisodeFile { Quality = QualityTypes.Bluray1080p, Proper = true };
secondFile = new EpisodeFile { Quality = QualityTypes.Bluray1080p, Proper = true };
var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = null } };
var doubleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = secondFile }, new Episode { EpisodeFile = null } };
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultSingle)).Returns(singleEpisodeList);
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultMulti)).Returns(doubleEpisodeList);
}
private void WithFirstFileUpgradable()
{
firstFile.Quality = QualityTypes.SDTV;
}
private void WithSecondFileUpgradable()
{
secondFile.Quality = QualityTypes.SDTV;
}
[Test]
public void should_return_false_if_single_episode_doesnt_exist_on_disk()
{
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultSingle)).Returns(new List<Episode>());
_upgradeDisk.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
}
[Test]
public void should_be_upgradable_if_only_episode_is_upgradable()
{
WithFirstFileUpgradable();
_upgradeDisk.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
}
[Test]
public void should_be_upgradable_if_both_episodes_are_upgradable()
{
WithFirstFileUpgradable();
WithSecondFileUpgradable();
_upgradeDisk.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void should_be_not_upgradable_if_both_episodes_are_not_upgradable()
{
_upgradeDisk.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
{
WithFirstFileUpgradable();
_upgradeDisk.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
{
WithSecondFileUpgradable();
_upgradeDisk.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
}
}
@@ -0,0 +1,118 @@
// ReSharper disable RedundantUsingDirective
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
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 UpgradeHistorySpecificationFixtrue : CoreTest
{
private UpgradeHistorySpecification _upgradeHistory;
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;
private Quality firstQuality;
private Quality secondQuality;
[SetUp]
public void Setup()
{
Mocker.Resolve<QualityUpgradeSpecification>();
_upgradeHistory = Mocker.Resolve<UpgradeHistorySpecification>();
var fakeSeries = Builder<Series>.CreateNew()
.With(c => c.QualityProfile = new QualityProfile { Cutoff = QualityTypes.Bluray1080p })
.Build();
parseResultMulti = new EpisodeParseResult
{
Series = fakeSeries,
Quality = new Quality(QualityTypes.DVD, true),
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
};
parseResultSingle = new EpisodeParseResult
{
Series = fakeSeries,
Quality = new Quality(QualityTypes.DVD, true),
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
};
firstQuality = new Quality(QualityTypes.Bluray1080p, true);
secondQuality = new Quality(QualityTypes.Bluray1080p, true);
var singleEpisodeList = new List<Episode> { new Episode { SeasonNumber = 12, EpisodeNumber = 3 } };
var doubleEpisodeList = new List<Episode> {
new Episode { SeasonNumber = 12, EpisodeNumber = 3 },
new Episode { SeasonNumber = 12, EpisodeNumber = 4 },
new Episode { SeasonNumber = 12, EpisodeNumber = 5 }
};
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultSingle)).Returns(singleEpisodeList);
Mocker.GetMock<EpisodeProvider>().Setup(c => c.GetEpisodesByParseResult(parseResultMulti)).Returns(doubleEpisodeList);
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 3)).Returns(firstQuality);
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 4)).Returns(secondQuality);
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 5)).Returns<Quality>(null);
}
private void WithFirstReportUpgradable()
{
firstQuality.QualityType = QualityTypes.SDTV;
}
private void WithSecondReportUpgradable()
{
secondQuality.QualityType = QualityTypes.SDTV;
}
[Test]
public void should_be_upgradable_if_only_episode_is_upgradable()
{
WithFirstReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultSingle).Should().BeTrue();
}
[Test]
public void should_be_upgradable_if_both_episodes_are_upgradable()
{
WithFirstReportUpgradable();
WithSecondReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeTrue();
}
[Test]
public void should_not_be_upgradable_if_both_episodes_are_not_upgradable()
{
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void should_be_not_upgradable_if_only_first_episodes_is_upgradable()
{
WithFirstReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void should_be_not_upgradable_if_only_second_episodes_is_upgradable()
{
WithSecondReportUpgradable();
_upgradeHistory.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
}
}
@@ -0,0 +1,103 @@
// ReSharper disable RedundantUsingDirective
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
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 UpgradePossibleSpecificationFixture : CoreTest
{
private void WithWebdlCutoff()
{
var profile = new QualityProfile { Cutoff = QualityTypes.WEBDL };
Mocker.GetMock<QualityProvider>().Setup(s => s.Get(It.IsAny<int>())).Returns(profile);
}
private Series _series;
private EpisodeFile _episodeFile;
private Episode _episode;
[SetUp]
public void SetUp()
{
_series = Builder<Series>.CreateNew()
.Build();
_episodeFile = Builder<EpisodeFile>.CreateNew()
.With(f => f.Quality = QualityTypes.SDTV)
.Build();
_episode = Builder<Episode>.CreateNew()
.With(e => e.EpisodeFileId = 0)
.With(e => e.SeriesId = _series.SeriesId)
.With(e => e.Series = _series)
.With(e => e.EpisodeFileId = _episodeFile.EpisodeFileId)
.With(e => e.EpisodeFile = _episodeFile)
.Build();
}
[Test]
public void IsUpgradePossible_should_return_true_if_no_episode_file_exists()
{
var episode = Builder<Episode>.CreateNew()
.With(e => e.EpisodeFileId = 0)
.Build();
//Act
bool result = Mocker.Resolve<UpgradePossibleSpecification>().IsSatisfiedBy(episode);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsUpgradePossible_should_return_true_if_current_episode_is_less_than_cutoff()
{
WithWebdlCutoff();
//Act
bool result = Mocker.Resolve<UpgradePossibleSpecification>().IsSatisfiedBy(_episode);
//Assert
result.Should().BeTrue();
}
[Test]
public void IsUpgradePossible_should_return_false_if_current_episode_is_equal_to_cutoff()
{
WithWebdlCutoff();
_episodeFile.Quality = QualityTypes.WEBDL;
//Act
bool result = Mocker.Resolve<UpgradePossibleSpecification>().IsSatisfiedBy(_episode);
//Assert
result.Should().BeFalse();
}
[Test]
public void IsUpgradePossible_should_return_false_if_current_episode_is_greater_than_cutoff()
{
WithWebdlCutoff();
_episodeFile.Quality = QualityTypes.Bluray720p;
//Act
bool result = Mocker.Resolve<UpgradePossibleSpecification>().IsSatisfiedBy(_episode);
//Assert
result.Should().BeFalse();
}
}
}