2013-04-15 01:41:39 +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-06 21:47:49 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
2013-06-09 07:14:38 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
2013-04-17 23:32:53 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-05-16 00:10:48 +00:00
|
|
|
public class DropFolderImportServiceFixture : CoreTest<DownloadedEpisodesImportService>
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
|
|
|
private EpisodeFile _fakeEpisodeFile;
|
|
|
|
|
|
|
|
private string[] _subFolders = new[] { "c:\\root\\foldername" };
|
|
|
|
private string[] _videoFiles = new[] { "c:\\root\\foldername\\video.ext" };
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
_fakeEpisodeFile = Builder<EpisodeFile>.CreateNew().Build();
|
|
|
|
|
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
|
|
|
|
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
|
|
|
.Returns("c:\\drop\\");
|
2013-04-15 01:41:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_import_file()
|
|
|
|
{
|
2013-06-09 06:20:38 +00:00
|
|
|
Subject.ProcessDownloadedEpisodesFolder();
|
2013-04-15 01:41:39 +00:00
|
|
|
|
|
|
|
VerifyImport();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_search_for_series_using_folder_name()
|
|
|
|
{
|
2013-06-09 06:20:38 +00:00
|
|
|
Subject.ProcessDownloadedEpisodesFolder();
|
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-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-05-10 23:53:50 +00:00
|
|
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
2013-04-15 01:41:39 +00:00
|
|
|
.Returns(true);
|
|
|
|
|
2013-06-09 06:20:38 +00:00
|
|
|
Subject.ProcessDownloadedEpisodesFolder();
|
2013-04-15 01:41:39 +00:00
|
|
|
VerifyNoImport();
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|