Fixed series scan tests.

pull/6/head
Taloth Saldono 8 years ago
parent 2abaef16f1
commit afe05189da

@ -18,28 +18,50 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
public class ScanFixture : CoreTest<DiskScanService> public class ScanFixture : CoreTest<DiskScanService>
{ {
private Series _series; private Series _series;
private string _rootFolder;
private string _otherSeriesFolder;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_rootFolder = @"C:\Test\TV".AsOsAgnostic();
_otherSeriesFolder = @"C:\Test\TV\OtherSeries".AsOsAgnostic();
var seriesFolder = @"C:\Test\TV\Series".AsOsAgnostic();
_series = Builder<Series>.CreateNew() _series = Builder<Series>.CreateNew()
.With(s => s.Path = @"C:\Test\TV\Series".AsOsAgnostic()) .With(s => s.Path = seriesFolder)
.Build(); .Build();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(It.IsAny<string>()))
.Returns(false);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetParentFolder(It.IsAny<string>())) .Setup(s => s.GetParentFolder(It.IsAny<string>()))
.Returns((string path) => Directory.GetParent(path).FullName); .Returns((string path) => Directory.GetParent(path).FullName);
} }
private void GivenParentFolderExists() private void GivenRootFolder(params string[] subfolders)
{ {
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(It.IsAny<string>())) .Setup(s => s.FolderExists(_rootFolder))
.Returns(true); .Returns(true);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(It.IsAny<string>())) .Setup(s => s.GetDirectories(_rootFolder))
.Returns(new[] { @"C:\Test\TV\Series2".AsOsAgnostic() }); .Returns(subfolders);
foreach (var folder in subfolders)
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(folder))
.Returns(true);
}
}
private void GivenSeriesFolder()
{
GivenRootFolder(_series.Path);
} }
private void GivenFiles(IEnumerable<string> files) private void GivenFiles(IEnumerable<string> files)
@ -50,12 +72,15 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_not_scan_if_series_root_folder_does_not_exist() public void should_not_scan_if_root_folder_does_not_exist()
{ {
Subject.Scan(_series); Subject.Scan(_series);
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.FolderExists(_series.Path), Times.Never());
Mocker.GetMock<IMediaFileTableCleanupService>() Mocker.GetMock<IMediaFileTableCleanupService>()
.Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Never()); .Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Never());
} }
@ -63,33 +88,62 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_if_series_root_folder_is_empty() public void should_not_scan_if_series_root_folder_is_empty()
{ {
Mocker.GetMock<IDiskProvider>() GivenRootFolder();
.Setup(s => s.FolderExists(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(It.IsAny<string>()))
.Returns(new string[0]);
Subject.Scan(_series); Subject.Scan(_series);
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.FolderExists(_series.Path), Times.Never());
Mocker.GetMock<IMediaFileTableCleanupService>() Mocker.GetMock<IMediaFileTableCleanupService>()
.Verify(v => v.Clean(It.IsAny<Series>(), new List<string>()), Times.Never()); .Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Never());
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _series), Times.Never());
} }
[Test] [Test]
public void should_clean_but_not_import_if_series_folder_does_not_exist() public void should_create_if_series_folder_does_not_exist_but_create_folder_enabled()
{ {
GivenParentFolderExists(); GivenRootFolder(_otherSeriesFolder);
Mocker.GetMock<IConfigService>()
.Setup(s => s.CreateEmptySeriesFolders)
.Returns(true);
Subject.Scan(_series);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(@"C:\Test\TV\Series")) .Verify(v => v.CreateFolder(_series.Path), Times.Once());
}
[Test]
public void should_not_create_if_series_folder_does_not_exist_and_create_folder_disabled()
{
GivenRootFolder(_otherSeriesFolder);
Mocker.GetMock<IConfigService>()
.Setup(s => s.CreateEmptySeriesFolders)
.Returns(false); .Returns(false);
Subject.Scan(_series); Subject.Scan(_series);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.CreateFolder(_series.Path), Times.Never());
}
[Test]
public void should_clean_but_not_import_if_series_folder_does_not_exist()
{
GivenRootFolder(_otherSeriesFolder);
Subject.Scan(_series);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.FolderExists(_series.Path), Times.Once());
Mocker.GetMock<IMediaFileTableCleanupService>() Mocker.GetMock<IMediaFileTableCleanupService>()
.Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Once()); .Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Once());
@ -98,18 +152,14 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
} }
[Test] [Test]
public void should_create_and_clean_but_not_import_if_series_folder_does_not_exist_but_create_folder_enabled() public void should_clean_but_not_import_if_series_folder_does_not_exist_and_create_folder_enabled()
{ {
GivenParentFolderExists(); GivenRootFolder(_otherSeriesFolder);
Mocker.GetMock<IConfigService>() Mocker.GetMock<IConfigService>()
.Setup(s => s.CreateEmptySeriesFolders) .Setup(s => s.CreateEmptySeriesFolders)
.Returns(true); .Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(@"C:\Test\TV\Series"))
.Returns(false);
Subject.Scan(_series); Subject.Scan(_series);
Mocker.GetMock<IMediaFileTableCleanupService>() Mocker.GetMock<IMediaFileTableCleanupService>()
@ -122,7 +172,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_find_files_at_root_of_series_folder() public void should_find_files_at_root_of_series_folder()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -139,7 +189,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_extras_subfolder() public void should_not_scan_extras_subfolder()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -162,7 +212,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_AppleDouble_subfolder() public void should_not_scan_AppleDouble_subfolder()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -180,9 +230,10 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_scan_extras_series_and_subfolders() public void should_scan_extras_series_and_subfolders()
{ {
GivenParentFolderExists();
_series.Path = @"C:\Test\TV\Extras".AsOsAgnostic(); _series.Path = @"C:\Test\TV\Extras".AsOsAgnostic();
GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_series.Path, "Extras", "file1.mkv").AsOsAgnostic(), Path.Combine(_series.Path, "Extras", "file1.mkv").AsOsAgnostic(),
@ -202,7 +253,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_subfolders_that_start_with_period() public void should_not_scan_subfolders_that_start_with_period()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -221,7 +272,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_subfolder_of_season_folder_that_starts_with_a_period() public void should_not_scan_subfolder_of_season_folder_that_starts_with_a_period()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -241,7 +292,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_Synology_eaDir() public void should_not_scan_Synology_eaDir()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -258,7 +309,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_thumb_folder() public void should_not_scan_thumb_folder()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
@ -275,9 +326,10 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_scan_dotHack_folder() public void should_scan_dotHack_folder()
{ {
GivenParentFolderExists();
_series.Path = @"C:\Test\TV\.hack".AsOsAgnostic(); _series.Path = @"C:\Test\TV\.hack".AsOsAgnostic();
GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {
Path.Combine(_series.Path, "Season 1", "file1.mkv").AsOsAgnostic(), Path.Combine(_series.Path, "Season 1", "file1.mkv").AsOsAgnostic(),
@ -293,7 +345,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_exclude_osx_metadata_files() public void should_exclude_osx_metadata_files()
{ {
GivenParentFolderExists(); GivenSeriesFolder();
GivenFiles(new List<string> GivenFiles(new List<string>
{ {

Loading…
Cancel
Save