Added MinSize check and revised tests.

pull/4/head
Taloth Saldono 11 years ago
parent ea6e858dbf
commit ff9887deaa

@ -15,51 +15,62 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
public class AcceptableSizeSpecificationFixture : CoreTest<AcceptableSizeSpecification>
{
private RemoteEpisode parseResultMultiSet;
private RemoteEpisode parseResultMulti;
private RemoteEpisode parseResultSingle;
private Series series30minutes;
private Series series60minutes;
private Series series;
private QualityDefinition qualityType;
[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
{
Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
Episodes = new List<Episode> { new Episode(), new Episode() }
};
{
Series = series,
Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
Episodes = new List<Episode> { new Episode(), new Episode() }
};
parseResultSingle = new RemoteEpisode
{
Series = series,
Release = new ReleaseInfo(),
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.SDTV, true) },
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()
.With(q => q.MinSize = 0)
.With(q => q.MinSize = 2)
.With(q => q.MaxSize = 10)
.With(q => q.Quality = Quality.SDTV)
.Build();
}
[Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_30_minute()
[TestCase(30, 50, false)]
[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;
parseResultSingle.Release.Size = 184572800;
series.Runtime = runtime;
parseResultSingle.Series = series;
parseResultSingle.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -67,111 +78,43 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(false);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
result.Should().BeTrue();
result.Should().Be(expectedResult);
}
[Test]
public void IsAcceptableSize_true_single_episode_not_first_or_last_60_minute()
[TestCase(30, 500, true)]
[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)
{
parseResultSingle.Series = series60minutes;
parseResultSingle.Release.Size = 368572800;
series.Runtime = runtime;
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_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<IEpisodeService>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(false);
.Returns(true);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute()
{
parseResultMulti.Series = series30minutes;
parseResultMulti.Release.Size = 184572800;
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();
result.Should().Be(expectedResult);
}
[Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute()
[TestCase(30, 50 * 2, false)]
[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)
{
parseResultMulti.Series = series30minutes;
parseResultMulti.Release.Size = 1.Gigabytes();
series.Runtime = runtime;
parseResultMulti.Series = series;
parseResultMulti.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -179,18 +122,22 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(false);
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
result.Should().BeFalse();
result.Should().Be(expectedResult);
}
[Test]
public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute()
[TestCase(30, 50 * 6, false)]
[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)
{
parseResultMulti.Series = series60minutes;
parseResultMulti.Release.Size = 10.Gigabytes();
series.Runtime = runtime;
parseResultMultiSet.Series = series;
parseResultMultiSet.Release.Size = sizeInMegaBytes.Megabytes();
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -198,97 +145,16 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>()))
.Returns(false);
bool result = Subject.IsSatisfiedBy(parseResultMultiSet, null);
bool result = Subject.IsSatisfiedBy(parseResultMulti, null);
result.Should().BeFalse();
result.Should().Be(expectedResult);
}
[Test]
public void IsAcceptableSize_true_single_episode_first_30_minute()
public void IsAcceptableSize_return_true_if_unlimited_30_minute()
{
parseResultSingle.Series = series30minutes;
parseResultSingle.Release.Size = 184572800;
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().BeTrue();
}
[Test]
public void IsAcceptableSize_true_single_episode_first_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(true);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
result.Should().BeTrue();
}
[Test]
public void IsAcceptableSize_false_single_episode_first_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(true);
bool result = Subject.IsSatisfiedBy(parseResultSingle, null);
result.Should().BeFalse();
}
[Test]
public void IsAcceptableSize_false_single_episode_first_60_minute()
{
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;
series.Runtime = 30;
parseResultSingle.Series = series;
parseResultSingle.Release.Size = 18457280000;
qualityType.MaxSize = 0;
@ -306,11 +172,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
}
[Test]
public void IsAcceptableSize_true_unlimited_60_minute()
public void IsAcceptableSize_return_true_if_unlimited_60_minute()
{
parseResultSingle.Series = series60minutes;
series.Runtime = 60;
parseResultSingle.Series = series;
parseResultSingle.Release.Size = 36857280000;
qualityType.MaxSize = 0;
@ -330,13 +195,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void IsAcceptableSize_should_treat_daily_series_as_single_episode()
{
parseResultSingle.Series = series60minutes;
series.Runtime = 60;
parseResultSingle.Series = series;
parseResultSingle.Series.SeriesType = SeriesTypes.Daily;
parseResultSingle.Release.Size = 300.Megabytes();
qualityType.MaxSize = (int)600.Megabytes();
qualityType.MaxSize = 10;
Mocker.GetMock<IQualityDefinitionService>().Setup(s => s.Get(Quality.SDTV)).Returns(qualityType);
@ -364,7 +229,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_always_return_false_if_unknow()
public void should_always_return_false_if_unknown()
{
var parseResult = new RemoteEpisode
{

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

Loading…
Cancel
Save