@ -22,15 +22,13 @@ namespace NzbDrone.Core.Test.MediaFiles
{
private string _droneFactory = "c:\\drop\\" . AsOsAgnostic ( ) ;
private string _downloadFolder = "c:\\drop_other\\Show.S01E01\\" . AsOsAgnostic ( ) ;
private string _downloadFile = "c:\\drop_other\\Show.S01E01.mkv" . AsOsAgnostic ( ) ;
private TrackedDownload _trackedDownload ;
[SetUp]
public void Setup ( )
{
Mocker . GetMock < IDiskProvider > ( ) . Setup ( c = > c . FolderExists ( It . IsAny < string > ( ) ) )
. Returns ( true ) ;
Mocker . GetMock < IConfigService > ( ) . SetupGet ( c = > c . DownloadedEpisodesFolder )
. Returns ( _droneFactory ) ;
@ -59,6 +57,18 @@ namespace NzbDrone.Core.Test.MediaFiles
} ;
}
private void GivenExistingFolder ( string path )
{
Mocker . GetMock < IDiskProvider > ( ) . Setup ( c = > c . FolderExists ( It . IsAny < string > ( ) ) )
. Returns ( true ) ;
}
private void GivenExistingFile ( string path )
{
Mocker . GetMock < IDiskProvider > ( ) . Setup ( c = > c . FileExists ( It . IsAny < string > ( ) ) )
. Returns ( true ) ;
}
private void GivenValidQueueItem ( )
{
Mocker . GetMock < ITrackedDownloadService > ( )
@ -69,6 +79,8 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_process_dronefactory_if_path_is_not_specified ( )
{
GivenExistingFolder ( _droneFactory ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessRootFolder ( It . IsAny < DirectoryInfo > ( ) ) , Times . Once ( ) ) ;
@ -77,8 +89,6 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_skip_import_if_dronefactory_doesnt_exist ( )
{
Mocker . GetMock < IDiskProvider > ( ) . Setup ( c = > c . FolderExists ( It . IsAny < string > ( ) ) ) . Returns ( false ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessRootFolder ( It . IsAny < DirectoryInfo > ( ) ) , Times . Never ( ) ) ;
@ -89,6 +99,8 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_ignore_downloadclientid_if_path_is_not_specified ( )
{
GivenExistingFolder ( _droneFactory ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) { DownloadClientId = "sab1" } ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessRootFolder ( It . IsAny < DirectoryInfo > ( ) ) , Times . Once ( ) ) ;
@ -97,14 +109,27 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_process_folder_if_downloadclientid_is_not_specified ( )
{
GivenExistingFolder ( _downloadFolder ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) { Path = _downloadFolder } ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessPath ( It . IsAny < string > ( ) , null , null ) , Times . Once ( ) ) ;
}
[Test]
public void should_process_file_if_downloadclientid_is_not_specified ( )
{
GivenExistingFile ( _downloadFile ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) { Path = _downloadFile } ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessPath ( It . IsAny < string > ( ) , null , null ) , Times . Once ( ) ) ;
}
[Test]
public void should_process_folder_with_downloadclientitem_if_available ( )
{
GivenExistingFolder ( _downloadFolder ) ;
GivenValidQueueItem ( ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) { Path = _downloadFolder , DownloadClientId = "sab1" } ) ;
@ -115,11 +140,23 @@ namespace NzbDrone.Core.Test.MediaFiles
[Test]
public void should_process_folder_without_downloadclientitem_if_not_available ( )
{
GivenExistingFolder ( _downloadFolder ) ;
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) { Path = _downloadFolder , DownloadClientId = "sab1" } ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessPath ( _downloadFolder , null , null ) , Times . Once ( ) ) ;
ExceptionVerification . ExpectedWarns ( 1 ) ;
}
[Test]
public void should_warn_if_neither_folder_or_file_exists ( )
{
Subject . Execute ( new DownloadedEpisodesScanCommand ( ) { Path = _downloadFolder } ) ;
Mocker . GetMock < IDownloadedEpisodesImportService > ( ) . Verify ( c = > c . ProcessPath ( It . IsAny < string > ( ) , null , null ) , Times . Never ( ) ) ;
ExceptionVerification . ExpectedWarns ( 1 ) ;
}
}
}