Added MinSize check and revised tests.

This commit is contained in:
Taloth Saldono 2014-02-15 11:51:52 +01:00
parent ea6e858dbf
commit ff9887deaa
2 changed files with 109 additions and 229 deletions

View File

@ -15,17 +15,29 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public class AcceptableSizeSpecificationFixture : CoreTest<AcceptableSizeSpecification> public class AcceptableSizeSpecificationFixture : CoreTest<AcceptableSizeSpecification>
{ {
private RemoteEpisode parseResultMultiSet;
private RemoteEpisode parseResultMulti; private RemoteEpisode parseResultMulti;
private RemoteEpisode parseResultSingle; private RemoteEpisode parseResultSingle;
private Series series30minutes; private Series series;
private Series series60minutes;
private QualityDefinition qualityType; private QualityDefinition qualityType;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
series = Builder<Series>.CreateNew()
.Build();
parseResultMultiSet = new RemoteEpisode
{
Series = series,
Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
Episodes = new List<Episode> { new Episode(), new Episode(), new Episode(), new Episode(), new Episode(), new Episode() }
};
parseResultMulti = new RemoteEpisode parseResultMulti = new RemoteEpisode
{ {
Series = series,
Release = new ReleaseInfo(), Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) }, ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
Episodes = new List<Episode> { new Episode(), new Episode() } Episodes = new List<Episode> { new Episode(), new Episode() }
@ -33,90 +45,32 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
parseResultSingle = new RemoteEpisode parseResultSingle = new RemoteEpisode
{ {
Series = series,
Release = new ReleaseInfo(), Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) }, ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
Episodes = new List<Episode> { new Episode() } 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<QualityDefinition>.CreateNew() qualityType = Builder<QualityDefinition>.CreateNew()
.With(q => q.MinSize = 0) .With(q => q.MinSize = 2)
.With(q => q.MaxSize = 10) .With(q => q.MaxSize = 10)
.With(q => q.Quality = Quality.SDTV) .With(q => q.Quality = Quality.SDTV)
.Build(); .Build();
} }
[Test] [TestCase(30, 50, false)]
public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute() [TestCase(30, 250, true)]
[TestCase(30, 500, false)]
[TestCase(60, 100, false)]
[TestCase(60, 500, true)]
[TestCase(60, 1000, false)]
public void IsAcceptableSize_single_episode(int runtime, int sizeInMegaBytes, bool expectedResult)
{ {
parseResultSingle.Series = series30minutes; series.Runtime = runtime;
parseResultSingle.Release.Size = 184572800; parseResultSingle.Series = series;
parseResultSingle.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType); Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -126,90 +80,18 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
bool result = Subject.IsSatisfiedBy(parseResultSingle, null); bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
result.Should().BeFalse(); result.Should().Be(expectedResult);
} }
[Test] [TestCase(30, 500, true)]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute() [TestCase(30, 1000, false)]
[TestCase(60, 1000, true)]
[TestCase(60, 2000, false)]
public void IsAcceptableSize_single_episode_first_or_last(int runtime, int sizeInMegaBytes, bool expectedResult)
{ {
parseResultMulti.Series = series30minutes; series.Runtime = runtime;
parseResultMulti.Release.Size = 184572800; parseResultSingle.Series = series;
parseResultSingle.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType); Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -217,78 +99,62 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(true); .Returns(true);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null); bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
result.Should().Be(expectedResult);
result.Should().BeTrue();
} }
[Test] [TestCase(30, 50 * 2, false)]
public void IsAcceptableSize_true_single_episode_first_60_minute() [TestCase(30, 250 * 2, true)]
[TestCase(30, 500 * 2, false)]
[TestCase(60, 100 * 2, false)]
[TestCase(60, 500 * 2, true)]
[TestCase(60, 1000 * 2, false)]
public void IsAcceptableSize_multi_episode(int runtime, int sizeInMegaBytes, bool expectedResult)
{ {
parseResultSingle.Series = series60minutes; series.Runtime = runtime;
parseResultSingle.Release.Size = 368572800; parseResultMulti.Series = series;
parseResultMulti.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType); Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
Mocker.GetMock<IEpisodeService>().Setup( Mocker.GetMock<IEpisodeService>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(true); .Returns(false);
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null); result.Should().Be(expectedResult);
result.Should().BeTrue();
} }
[Test] [TestCase(30, 50 * 6, false)]
public void IsAcceptableSize_false_single_episode_first_30_minute() [TestCase(30, 250 * 6, true)]
[TestCase(30, 500 * 6, false)]
[TestCase(60, 100 * 6, false)]
[TestCase(60, 500 * 6, true)]
[TestCase(60, 1000 * 6, false)]
public void IsAcceptableSize_multiset_episode(int runtime, int sizeInMegaBytes, bool expectedResult)
{ {
parseResultSingle.Series = series30minutes; series.Runtime = runtime;
parseResultSingle.Release.Size = 1.Gigabytes(); parseResultMultiSet.Series = series;
parseResultMultiSet.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType); Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
Mocker.GetMock<IEpisodeService>().Setup( Mocker.GetMock<IEpisodeService>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>())) s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(true); .Returns(false);
bool result = Subject.IsSatisfiedBy(parseResultMultiSet, null);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null); result.Should().Be(expectedResult);
result.Should().BeFalse();
} }
[Test] [Test]
public void IsAcceptableSize_false_single_episode_first_60_minute() public void IsAcceptableSize_return_true_if_unlimited_30_minute()
{ {
series.Runtime = 30;
parseResultSingle.Series = series;
parseResultSingle.Series = series60minutes;
parseResultSingle.Release.Size = 10.Gigabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).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; parseResultSingle.Release.Size = 18457280000;
qualityType.MaxSize = 0; qualityType.MaxSize = 0;
@ -306,11 +172,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
} }
[Test] [Test]
public void IsAcceptableSize_true_unlimited_60_minute() public void IsAcceptableSize_return_true_if_unlimited_60_minute()
{ {
series.Runtime = 60;
parseResultSingle.Series = series;
parseResultSingle.Series = series60minutes;
parseResultSingle.Release.Size = 36857280000; parseResultSingle.Release.Size = 36857280000;
qualityType.MaxSize = 0; qualityType.MaxSize = 0;
@ -330,13 +195,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test] [Test]
public void IsAcceptableSize_should_treat_daily_series_as_single_episode() public void IsAcceptableSize_should_treat_daily_series_as_single_episode()
{ {
series.Runtime = 60;
parseResultSingle.Series = series60minutes; parseResultSingle.Series = series;
parseResultSingle.Series.SeriesType = SeriesTypes.Daily; parseResultSingle.Series.SeriesType = SeriesTypes.Daily;
parseResultSingle.Release.Size = 300.Megabytes(); parseResultSingle.Release.Size = 300.Megabytes();
qualityType.MaxSize = (int)600.Megabytes(); qualityType.MaxSize = 10;
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType); Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -364,7 +229,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test] [Test]
public void should_always_return_false_if_unknow() public void should_always_return_false_if_unknown()
{ {
var parseResult = new RemoteEpisode var parseResult = new RemoteEpisode
{ {

View File

@ -46,19 +46,33 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
var qualityDefinition = _qualityDefinitionService.Get(quality); var qualityDefinition = _qualityDefinitionService.Get(quality);
{
var minSize = qualityDefinition.MinSize.Megabytes();
//Multiply maxSize by Series.Runtime
minSize = minSize * subject.Series.Runtime * subject.Episodes.Count;
//If the parsed size is smaller than minSize we don't want it
if (subject.Release.Size < minSize)
{
_logger.Trace("Item: {0}, Size: {1} is smaller than minimum allowed size ({2}), rejecting.", subject, subject.Release.Size, minSize);
return false;
}
}
if (qualityDefinition.MaxSize == 0) if (qualityDefinition.MaxSize == 0)
{ {
_logger.Trace("Max size is 0 (unlimited) - skipping check."); _logger.Trace("Max size is 0 (unlimited) - skipping check.");
return true;
} }
else
{
var maxSize = qualityDefinition.MaxSize.Megabytes(); var maxSize = qualityDefinition.MaxSize.Megabytes();
//Multiply maxSize by Series.Runtime //Multiply maxSize by Series.Runtime
maxSize = maxSize * subject.Series.Runtime * subject.Episodes.Count; maxSize = maxSize * subject.Series.Runtime * subject.Episodes.Count;
//Check if there was only one episode parsed and it is the first //Check if there was only one episode parsed and it is the first
if (subject.Episodes.Count == 1 && subject.Episodes.First().EpisodeNumber == 1) if (subject.Episodes.Count == 1 && _episodeService.IsFirstOrLastEpisodeOfSeason(subject.Episodes.First().Id))
{ {
maxSize = maxSize * 2; maxSize = maxSize * 2;
} }
@ -69,6 +83,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
_logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Release.Size, maxSize); _logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Release.Size, maxSize);
return false; return false;
} }
}
_logger.Trace("Item: {0}, meets size constraints.", subject); _logger.Trace("Item: {0}, meets size constraints.", subject);
return true; return true;