Better sample checks

Fixed: Sample checking relies on runtime instead of file size (Windows)
Fixed: Minimum file size for 1080p releases is now 140MB (lower will be considered samples)
This commit is contained in:
Mark McDowall
2013-11-03 22:39:37 -08:00
parent e7ac2247ab
commit 77a5fd62d2
4 changed files with 114 additions and 85 deletions
@@ -7,6 +7,7 @@ using NUnit.Framework;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
@@ -36,106 +37,46 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
Episodes = episodes,
Series = _series
Series = _series,
Quality = new QualityModel(Quality.HDTV720p)
};
}
private void WithDailySeries()
{
_series.SeriesType = SeriesTypes.Daily;
}
private void WithSeasonZero()
{
_localEpisode.Episodes[0].SeasonNumber = 0;
}
private void WithFileSize(long size)
private void GivenFileSize(long size)
{
_localEpisode.Size = size;
}
private void WithLength(int minutes)
private void GivenRuntime(int seconds)
{
Mocker.GetMock<IVideoFileInfoReader>()
.Setup(s => s.GetRunTime(It.IsAny<String>()))
.Returns(new TimeSpan(0, 0, minutes, 0));
.Returns(new TimeSpan(0, 0, seconds));
}
[Test]
public void should_return_true_if_series_is_daily()
{
WithDailySeries();
_series.SeriesType = SeriesTypes.Daily;
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_season_zero()
{
WithSeasonZero();
_localEpisode.Episodes[0].SeasonNumber = 0;
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_false_if_undersize_and_under_length()
public void should_return_true_for_existing_file()
{
WithFileSize(10.Megabytes());
WithLength(1);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_true_if_undersize()
{
WithFileSize(10.Megabytes());
WithLength(10);
_localEpisode.ExistingFile = true;
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_under_length()
{
WithFileSize(100.Megabytes());
WithLength(1);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_over_size_and_length()
{
WithFileSize(100.Megabytes());
WithLength(10);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_not_check_lenght_if_file_is_large_enough()
{
WithFileSize(100.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
}
[Test]
public void should_log_error_if_run_time_is_0_and_under_sample_size()
{
WithFileSize(40.Megabytes());
WithLength(0);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void should_skip_check_for_flv_file()
public void should_return_true_for_flv()
{
_localEpisode.Path = @"C:\Test\some.show.s01e01.flv";
@@ -143,5 +84,66 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
}
[Test]
public void should_not_run_runtime_check_on_linux()
{
LinuxOnly();
GivenFileSize(1000.Megabytes());
Subject.IsSatisfiedBy(_localEpisode);
Mocker.GetMock<IVideoFileInfoReader>().Verify(v => v.GetRunTime(It.IsAny<String>()), Times.Never());
}
[Test]
public void should_run_runtime_check_on_windows()
{
GivenRuntime(120);
GivenFileSize(1000.Megabytes());
Subject.IsSatisfiedBy(_localEpisode);
Mocker.GetMock<IVideoFileInfoReader>().Verify(v => v.GetRunTime(It.IsAny<String>()), Times.Once());
}
[Test]
public void should_return_false_if_runtime_is_less_than_minimum()
{
GivenRuntime(60);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_true_if_runtime_greater_than_than_minimum()
{
GivenRuntime(120);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_false_if_file_size_is_under_minimum()
{
LinuxOnly();
GivenRuntime(120);
GivenFileSize(20.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_false_if_file_size_is_under_minimum_for_larger_limits()
{
LinuxOnly();
GivenRuntime(120);
GivenFileSize(120.Megabytes());
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
}
}