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