Fixed: DownloadedEpisodesScan API command couldn't be used to process individual files.

This commit is contained in:
Taloth Saldono 2016-02-15 21:55:53 +01:00
parent f25f5abced
commit 72f0085ef7
2 changed files with 46 additions and 10 deletions

View File

@ -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);
}
}
}

View File

@ -54,17 +54,16 @@ namespace NzbDrone.Core.MediaFiles
return _downloadedEpisodesImportService.ProcessRootFolder(new DirectoryInfo(downloadedEpisodesFolder));
}
private List<ImportResult> ProcessFolder(DownloadedEpisodesScanCommand message)
private List<ImportResult> ProcessPath(DownloadedEpisodesScanCommand message)
{
if (!_diskProvider.FolderExists(message.Path))
if (!_diskProvider.FolderExists(message.Path) && !_diskProvider.FileExists(message.Path))
{
_logger.Warn("Folder specified for import scan [{0}] doesn't exist.", message.Path);
_logger.Warn("Folder/File specified for import scan [{0}] doesn't exist.", message.Path);
return new List<ImportResult>();
}
if (message.DownloadClientId.IsNotNullOrWhiteSpace())
{
var trackedDownload = _trackedDownloadService.Find(message.DownloadClientId);
if (trackedDownload != null)
@ -90,7 +89,7 @@ namespace NzbDrone.Core.MediaFiles
if (message.Path.IsNotNullOrWhiteSpace())
{
importResults = ProcessFolder(message);
importResults = ProcessPath(message);
}
else
{