mirror of https://github.com/Sonarr/Sonarr
Fixed broken tests
This commit is contained in:
parent
df9ab3b426
commit
bc7e543c4d
|
@ -4,6 +4,7 @@ using FizzWare.NBuilder;
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
@ -17,7 +18,6 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|||
{
|
||||
private EpisodeFile _fakeEpisodeFile;
|
||||
|
||||
|
||||
private string[] _subFolders = new[] { "c:\\root\\foldername" };
|
||||
private string[] _videoFiles = new[] { "c:\\root\\foldername\\video.ext" };
|
||||
|
||||
|
@ -32,6 +32,9 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
.Returns(_subFolders);
|
||||
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
||||
.Returns("c:\\drop\\");
|
||||
}
|
||||
|
||||
private void WithOldWrite()
|
||||
|
@ -55,7 +58,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|||
[Test]
|
||||
public void should_import_file()
|
||||
{
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
Subject.ProcessDownloadedEpiosdesFolder();
|
||||
|
||||
VerifyImport();
|
||||
}
|
||||
|
@ -65,46 +68,29 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|||
{
|
||||
WithRecentFolderWrite();
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
Subject.ProcessDownloadedEpiosdesFolder();
|
||||
|
||||
VerifyNoImport();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_folder_name()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
Subject.ProcessDownloadedEpiosdesFolder();
|
||||
|
||||
Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_file_name()
|
||||
{
|
||||
/*WithOldWrite();
|
||||
WithValidSeries();
|
||||
WithImportableFiles();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
||||
Subject.ProcessDownload(droppedFolder);
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Verify(c => c.Scan(_fakeSeries, It.IsAny<string>()));*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void all_imported_files_should_be_moved()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns(_fakeEpisodeFile);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
Subject.ProcessDownloadedEpiosdesFolder();
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(_fakeEpisodeFile, true), Times.Once());
|
||||
}
|
||||
|
@ -115,12 +101,11 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|||
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns<EpisodeFile>(null);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
Subject.ProcessDownloadedEpiosdesFolder();
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<bool>()), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_folder_is_in_use_by_another_process()
|
||||
{
|
||||
|
@ -128,19 +113,16 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|||
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(true);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
Subject.ProcessDownloadedEpiosdesFolder();
|
||||
VerifyNoImport();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void VerifyNoImport()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
|
||||
private void VerifyImport()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()),
|
||||
|
|
|
@ -37,6 +37,48 @@ namespace NzbDrone.Core.MediaFiles
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public void ProcessDownloadedEpiosdesFolder()
|
||||
{
|
||||
//TODO: We should also process the download client's category folder
|
||||
var downloadedEpisodesFolder = _configService.DownloadedEpisodesFolder;
|
||||
|
||||
if (String.IsNullOrEmpty(downloadedEpisodesFolder))
|
||||
{
|
||||
_logger.Warn("Downloaded Episodes Folder is not configured");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var subfolder in _diskProvider.GetDirectories(downloadedEpisodesFolder))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_seriesService.SeriesPathExists(subfolder))
|
||||
{
|
||||
ProcessSubFolder(new DirectoryInfo(subfolder));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("An error has occurred while importing folder: " + subfolder, e);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var videoFile in _diskScanService.GetVideoFiles(downloadedEpisodesFolder, false))
|
||||
{
|
||||
try
|
||||
{
|
||||
var series = _parsingService.GetSeries(videoFile);
|
||||
ProcessVideoFile(videoFile, series);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("An error has occurred while importing video file" + videoFile, ex);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: cleanup empty folders
|
||||
}
|
||||
|
||||
public void ProcessSubFolder(DirectoryInfo subfolderInfo)
|
||||
{
|
||||
if (_diskProvider.GetLastFolderWrite(subfolderInfo.FullName).AddMinutes(2) > DateTime.UtcNow)
|
||||
|
@ -85,44 +127,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
public void Execute(DownloadedEpisodesScanCommand message)
|
||||
{
|
||||
//TODO: We should also process the download client's category folder
|
||||
var downloadedEpisodesFolder = _configService.DownloadedEpisodesFolder;
|
||||
|
||||
if (String.IsNullOrEmpty(downloadedEpisodesFolder))
|
||||
{
|
||||
_logger.Warn("Downloaded Episodes Folder is not configured");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var subfolder in _diskProvider.GetDirectories(downloadedEpisodesFolder))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_seriesService.SeriesPathExists(subfolder))
|
||||
{
|
||||
ProcessSubFolder(new DirectoryInfo(subfolder));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("An error has occurred while importing folder: " + subfolder, e);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var videoFile in _diskScanService.GetVideoFiles(downloadedEpisodesFolder, false))
|
||||
{
|
||||
try
|
||||
{
|
||||
var series = _parsingService.GetSeries(videoFile);
|
||||
ProcessVideoFile(videoFile, series);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("An error has occurred while importing video file" + videoFile, ex);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: cleanup empty folders
|
||||
ProcessDownloadedEpiosdesFolder();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue