sample folder moved to new testcop style.

This commit is contained in:
Keivan Beigi
2013-09-10 10:54:59 -07:00
parent 9c1f991d1c
commit 56f695577c
14 changed files with 34 additions and 47 deletions
@@ -0,0 +1,124 @@
using System;
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification>
{
private Series _series;
private LocalEpisode _localEpisode;
private String _rootFolder;
[SetUp]
public void Setup()
{
_rootFolder = @"C:\Test\TV".AsOsAgnostic();
_series = Builder<Series>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard)
.With(s => s.Path = Path.Combine(_rootFolder, "30 Rock"))
.Build();
var episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.Build()
.ToList();
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
Episodes = episodes,
Series = _series
};
}
private void GivenFileSize(long size)
{
_localEpisode.Size = size;
}
private void GivenFreeSpace(long? size)
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
.Returns(size);
}
[Test]
public void should_reject_when_there_isnt_enough_disk_space()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(80.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_reject_when_there_isnt_enough_space_for_file_plus_100mb_padding()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(150.Megabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_accept_when_there_is_enough_disk_space()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(1.Gigabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_use_series_paths_parent_for_free_space_check()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(1.Gigabytes());
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetAvailableSpace(_rootFolder), Times.Once());
}
[Test]
public void should_pass_if_free_space_is_null()
{
GivenFileSize(100.Megabytes());
GivenFreeSpace(null);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_pass_if_exception_is_thrown()
{
GivenFileSize(100.Megabytes());
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
.Throws(new TestException());
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
ExceptionVerification.ExpectedErrors(1);
}
}
}
@@ -0,0 +1,88 @@
using System.IO;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class NotInUseSpecificationFixture : CoreTest<NotInUseSpecification>
{
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
Size = 100,
Series = Builder<Series>.CreateNew().Build()
};
}
private void GivenChildOfSeries()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
.Returns(true);
}
private void GivenNewFile()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
.Returns(false);
}
[Test]
public void should_return_true_if_file_is_under_series_folder()
{
GivenChildOfSeries();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_not_check_for_file_in_use_if_child_of_series_folder()
{
GivenChildOfSeries();
Subject.IsSatisfiedBy(_localEpisode);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.IsFileLocked(It.IsAny<FileInfo>()), Times.Never());
}
[Test]
public void should_return_false_if_file_is_in_use()
{
GivenNewFile();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
.Returns(true);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_true_if_file_is_not_in_use()
{
GivenNewFile();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
.Returns(false);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
}
}
@@ -0,0 +1,147 @@
using System;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class NotSampleSpecificationFixture : CoreTest<NotSampleSpecification>
{
private Series _series;
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard)
.Build();
var episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.Build()
.ToList();
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
Episodes = episodes,
Series = _series
};
}
private void WithDailySeries()
{
_series.SeriesType = SeriesTypes.Daily;
}
private void WithSeasonZero()
{
_localEpisode.Episodes[0].SeasonNumber = 0;
}
private void WithFileSize(long size)
{
_localEpisode.Size = size;
}
private void WithLength(int minutes)
{
Mocker.GetMock<IVideoFileInfoReader>()
.Setup(s => s.GetRunTime(It.IsAny<String>()))
.Returns(new TimeSpan(0, 0, minutes, 0));
}
[Test]
public void should_return_true_if_series_is_daily()
{
WithDailySeries();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_season_zero()
{
WithSeasonZero();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_false_if_undersize_and_under_length()
{
WithFileSize(10.Megabytes());
WithLength(1);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_true_if_undersize()
{
WithFileSize(10.Megabytes());
WithLength(10);
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()
{
_localEpisode.Path = @"C:\Test\some.show.s01e01.flv";
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
}
}
}
@@ -0,0 +1,72 @@
using System;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class NotUnpackingSpecificationFixture : CoreTest<NotUnpackingSpecification>
{
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
Mocker.GetMock<IConfigService>()
.SetupGet(s => s.DownloadClientWorkingFolders)
.Returns("_UNPACK_|_FAILED_");
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\Unsorted TV\30.rock\30.rock.s01e01.avi".AsOsAgnostic(),
Size = 100,
Series = Builder<Series>.CreateNew().Build()
};
}
private void GivenInWorkingFolder()
{
_localEpisode.Path = @"C:\Test\Unsorted TV\_UNPACK_30.rock\30.rock.s01e01.avi".AsOsAgnostic();
}
private void GivenLastWriteTimeUtc(DateTime time)
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetLastFileWrite(It.IsAny<string>()))
.Returns(time);
}
[Test]
public void should_return_true_if_not_in_working_folder()
{
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_when_in_old_working_folder()
{
GivenInWorkingFolder();
GivenLastWriteTimeUtc(DateTime.UtcNow.AddHours(-1));
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_false_if_in_working_folder_and_last_write_time_was_recent()
{
GivenInWorkingFolder();
GivenLastWriteTimeUtc(DateTime.UtcNow);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
}
}
@@ -0,0 +1,153 @@
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Marr.Data;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
{
[TestFixture]
public class UpgradeSpecificationFixture : CoreTest<UpgradeSpecification>
{
private Series _series;
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateNew()
.With(s => s.SeriesType = SeriesTypes.Standard)
.Build();
_localEpisode = new LocalEpisode
{
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
Quality = new QualityModel(Quality.HDTV720p, false)
};
}
[Test]
public void should_return_true_if_no_existing_episodeFile()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 0)
.With(e => e.EpisodeFile = null)
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_no_existing_episodeFile_for_multi_episodes()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFileId = 0)
.With(e => e.EpisodeFile = null)
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_upgrade_for_existing_episodeFile()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Quality = new QualityModel(Quality.SDTV, false)
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_true_if_upgrade_for_existing_episodeFile_for_multi_episodes()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Quality = new QualityModel(Quality.SDTV, false)
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
}
[Test]
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Quality = new QualityModel(Quality.Bluray720p, false)
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile_for_multi_episodes()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Quality = new QualityModel(Quality.Bluray720p, false)
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
[Test]
public void should_return_false_if_not_an_upgrade_for_one_existing_episodeFile_for_multi_episode()
{
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
.TheFirst(1)
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Quality = new QualityModel(Quality.SDTV, false)
}))
.TheNext(1)
.With(e => e.EpisodeFileId = 2)
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
new EpisodeFile
{
Quality = new QualityModel(Quality.Bluray720p, false)
}))
.Build()
.ToList();
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
}
}
}