2013-07-18 04:50:58 +00:00
|
|
|
using System;
|
2013-07-06 21:47:49 +00:00
|
|
|
using System.Collections.Generic;
|
2013-04-15 01:41:39 +00:00
|
|
|
using System.IO;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2013-05-16 00:25:51 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-07-16 17:55:11 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.Commands;
|
2013-07-06 21:47:49 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
2013-04-17 23:32:53 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
2013-07-18 04:50:58 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-07-18 04:50:58 +00:00
|
|
|
using NzbDrone.Core.Tv;
|
2013-07-16 17:55:11 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
2013-09-10 17:54:59 +00:00
|
|
|
namespace NzbDrone.Core.Test.MediaFiles
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-09-10 17:54:59 +00:00
|
|
|
public class DownloadedEpisodesImportServiceFixture : CoreTest<DownloadedEpisodesImportService>
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
2013-07-26 05:29:59 +00:00
|
|
|
private string[] _subFolders = new[] { "c:\\root\\foldername".AsOsAgnostic() };
|
|
|
|
private string[] _videoFiles = new[] { "c:\\root\\foldername\\video.ext".AsOsAgnostic() };
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2013-04-15 05:27:32 +00:00
|
|
|
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
2013-04-15 01:41:39 +00:00
|
|
|
.Returns(_videoFiles);
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
2013-04-15 01:41:39 +00:00
|
|
|
.Returns(_subFolders);
|
2013-05-16 00:25:51 +00:00
|
|
|
|
2013-07-16 17:55:11 +00:00
|
|
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
|
|
|
|
.Returns(true);
|
|
|
|
|
2013-05-16 00:25:51 +00:00
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
2013-07-26 05:29:59 +00:00
|
|
|
.Returns("c:\\drop\\".AsOsAgnostic());
|
2013-07-16 17:55:11 +00:00
|
|
|
|
2013-07-18 04:50:58 +00:00
|
|
|
Mocker.GetMock<IImportApprovedEpisodes>()
|
|
|
|
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true))
|
|
|
|
.Returns(new List<ImportDecision>());
|
2013-04-15 01:41:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:50:58 +00:00
|
|
|
private void GivenValidSeries()
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
2013-07-18 04:50:58 +00:00
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
.Setup(s => s.GetSeries(It.IsAny<String>()))
|
|
|
|
.Returns(Builder<Series>.CreateNew().Build());
|
2013-04-15 01:41:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_search_for_series_using_folder_name()
|
|
|
|
{
|
2013-07-16 17:55:11 +00:00
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
|
2013-04-17 23:32:53 +00:00
|
|
|
Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
|
2013-06-09 07:14:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 17:55:11 +00:00
|
|
|
[Test]
|
|
|
|
public void should_skip_import_if_dropfolder_doesnt_exist()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>())).Returns(false);
|
|
|
|
|
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetDirectories(It.IsAny<string>()), Times.Never());
|
|
|
|
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Never());
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
[Test]
|
2013-07-06 21:47:49 +00:00
|
|
|
public void should_skip_if_file_is_in_use_by_another_process()
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
2013-09-12 06:52:37 +00:00
|
|
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<string>()))
|
2013-04-15 01:41:39 +00:00
|
|
|
.Returns(true);
|
|
|
|
|
2013-07-16 17:55:11 +00:00
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
VerifyNoImport();
|
|
|
|
}
|
|
|
|
|
2013-07-18 04:50:58 +00:00
|
|
|
[Test]
|
|
|
|
public void should_not_import_if_folder_is_a_series_path()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<ISeriesService>()
|
|
|
|
.Setup(s => s.SeriesPathExists(It.IsAny<String>()))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskScanService>()
|
|
|
|
.Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
|
|
|
.Returns(new string[0]);
|
|
|
|
|
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
.Verify(v => v.GetSeries(It.IsAny<String>()), Times.Never());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_delete_folder_if_no_files_were_imported()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IImportApprovedEpisodes>()
|
|
|
|
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), false))
|
|
|
|
.Returns(new List<ImportDecision>());
|
|
|
|
|
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
2013-08-03 03:01:16 +00:00
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-07-18 04:50:58 +00:00
|
|
|
.Verify(v => v.GetFolderSize(It.IsAny<String>()), Times.Never());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_delete_folder_if_files_were_imported()
|
|
|
|
{
|
|
|
|
GivenValidSeries();
|
|
|
|
|
|
|
|
var localEpisode = new LocalEpisode();
|
|
|
|
|
|
|
|
var imported = new List<ImportDecision>();
|
|
|
|
imported.Add(new ImportDecision(localEpisode));
|
|
|
|
|
|
|
|
Mocker.GetMock<IMakeImportDecision>()
|
2013-07-23 05:50:32 +00:00
|
|
|
.Setup(s => s.GetImportDecisions(It.IsAny<IEnumerable<String>>(), It.IsAny<Series>(), true))
|
2013-07-18 04:50:58 +00:00
|
|
|
.Returns(imported);
|
|
|
|
|
|
|
|
Mocker.GetMock<IImportApprovedEpisodes>()
|
|
|
|
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true))
|
|
|
|
.Returns(imported);
|
|
|
|
|
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Once());
|
|
|
|
}
|
|
|
|
|
2013-07-23 06:46:42 +00:00
|
|
|
[TestCase("_UNPACK_")]
|
|
|
|
[TestCase("_FAILED_")]
|
|
|
|
public void should_remove_unpack_from_folder_name(string prefix)
|
|
|
|
{
|
|
|
|
var folderName = "30.rock.s01e01.pilot.hdtv-lol";
|
2013-07-26 05:29:59 +00:00
|
|
|
var folders = new[] { String.Format(@"C:\Test\Unsorted\{0}{1}", prefix, folderName).AsOsAgnostic() };
|
2013-07-23 06:46:42 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(c => c.GetDirectories(It.IsAny<string>()))
|
|
|
|
.Returns(folders);
|
|
|
|
|
|
|
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
.Verify(v => v.GetSeries(folderName), Times.Once());
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
.Verify(v => v.GetSeries(It.Is<String>(s => s.StartsWith(prefix))), Times.Never());
|
|
|
|
}
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
private void VerifyNoImport()
|
|
|
|
{
|
2013-07-06 21:47:49 +00:00
|
|
|
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true),
|
2013-04-15 01:41:39 +00:00
|
|
|
Times.Never());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void VerifyImport()
|
|
|
|
{
|
2013-07-06 21:47:49 +00:00
|
|
|
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true),
|
2013-04-15 01:41:39 +00:00
|
|
|
Times.Once());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|