2011-10-23 02:31:28 +00:00
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2011-11-13 04:07:06 +00:00
|
|
|
using NzbDrone.Common;
|
2013-02-19 06:01:03 +00:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-10-23 02:31:28 +00:00
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-10-24 05:54:09 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 00:22:18 +00:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-02-17 05:44:06 +00:00
|
|
|
public class ProcessDownloadFixture : CoreTest
|
2011-10-23 02:31:28 +00:00
|
|
|
{
|
2012-02-07 05:08:07 +00:00
|
|
|
Series fakeSeries;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2012-08-09 01:17:44 +00:00
|
|
|
fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.Path = @"C:\Test\TV\30 Rock")
|
|
|
|
.Build();
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
2012-01-23 04:59:23 +00:00
|
|
|
|
|
|
|
private void WithOldWrite()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(c => c.GetLastDirectoryWrite(It.IsAny<String>()))
|
|
|
|
.Returns(DateTime.Now.AddDays(-5));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithRecentWrite()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(c => c.GetLastDirectoryWrite(It.IsAny<String>()))
|
|
|
|
.Returns(DateTime.UtcNow);
|
|
|
|
}
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
private void WithValidSeries()
|
|
|
|
{
|
2013-02-19 06:56:02 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-20 02:05:15 +00:00
|
|
|
.Setup(c => c.GetByTitle(It.IsAny<string>()))
|
2012-02-07 05:08:07 +00:00
|
|
|
.Returns(fakeSeries);
|
2012-10-20 06:46:12 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(c => c.FolderExists(fakeSeries.Path))
|
|
|
|
.Returns(true);
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithImportableFiles()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<DiskScanProvider>()
|
|
|
|
.Setup(c => c.Scan(It.IsAny<Series>(), It.IsAny<string>()))
|
|
|
|
.Returns(Builder<EpisodeFile>.CreateListOfSize(1).Build().ToList());
|
|
|
|
}
|
|
|
|
|
2012-08-09 01:17:44 +00:00
|
|
|
private void WithLotsOfFreeDiskSpace()
|
|
|
|
{
|
2013-02-17 04:33:56 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
|
2012-08-09 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithImportedFiles(string droppedFolder)
|
|
|
|
{
|
|
|
|
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(f => f.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.Build().ToList();
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder)).Returns(fakeEpisodeFiles);
|
|
|
|
}
|
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
[Test]
|
|
|
|
public void should_skip_if_folder_is_tagged_and_too_fresh()
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
WithStrictMocker();
|
2012-01-23 04:59:23 +00:00
|
|
|
WithRecentWrite();
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
|
|
|
droppedFolder.Create();
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_continue_processing_if_folder_is_tagged_and_not_fresh()
|
|
|
|
{
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
|
|
|
droppedFolder.Create();
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null).Verifiable();
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2012-01-15 03:17:23 +00:00
|
|
|
ExceptionVerification.IgnoreWarns();
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_search_for_series_using_title_without_status()
|
|
|
|
{
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\_unpack_The Office - S01E01 - Episode Title");
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns<Series>(null).Verifiable();
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2012-01-15 03:17:23 +00:00
|
|
|
ExceptionVerification.IgnoreWarns();
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
[Test]
|
|
|
|
public void should_search_for_series_using_folder_name()
|
|
|
|
{
|
|
|
|
WithOldWrite();
|
|
|
|
WithValidSeries();
|
|
|
|
WithImportableFiles();
|
|
|
|
|
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskScanProvider>()
|
|
|
|
.Verify(c=>c.Scan(fakeSeries, It.IsAny<string>()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[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");
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskScanProvider>()
|
|
|
|
.Verify(c => c.Scan(fakeSeries, It.IsAny<string>()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
[Test]
|
2012-01-15 03:17:23 +00:00
|
|
|
[Ignore("Disabled tagging")]
|
2011-10-23 02:31:28 +00:00
|
|
|
public void when_series_isnt_found_folder_should_be_tagged_as_unknown_series()
|
|
|
|
{
|
|
|
|
//Setup
|
2011-12-15 04:15:53 +00:00
|
|
|
WithStrictMocker();
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
|
|
|
|
|
|
|
var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title";
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns<Series>(null);
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
|
2011-10-23 02:31:28 +00:00
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-12-20 00:58:26 +00:00
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-01-15 03:17:23 +00:00
|
|
|
[Ignore("Disabled tagging")]
|
2011-10-23 02:31:28 +00:00
|
|
|
public void when_no_files_are_imported_folder_should_be_tagged_with_parse_error()
|
|
|
|
{
|
|
|
|
//Setup
|
2011-12-15 04:15:53 +00:00
|
|
|
WithStrictMocker();
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
|
|
|
|
|
|
|
var taggedFolder = @"C:\Test\Unsorted TV\_ParseError_The Office - S01E01 - Episode Title";
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.Title = "The Office")
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(new List<EpisodeFile>());
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-12-20 00:58:26 +00:00
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-15 03:17:23 +00:00
|
|
|
[Ignore("Disabled tagging")]
|
2011-10-23 02:31:28 +00:00
|
|
|
public void when_no_file_are_imported_and_folder_size_isnt_small_enought_folder_should_be_tagged_unknown()
|
|
|
|
{
|
|
|
|
//Setup
|
2011-12-15 04:15:53 +00:00
|
|
|
WithStrictMocker();
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
|
|
|
|
2011-10-25 04:34:48 +00:00
|
|
|
var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.Title = "The Office")
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
|
|
|
.All()
|
|
|
|
.With(f => f.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.Build().ToList();
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
|
2012-07-12 21:08:21 +00:00
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
|
2011-10-23 02:31:28 +00:00
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-12-20 00:58:26 +00:00
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 04:34:48 +00:00
|
|
|
[TestCase(@"\_UnknownSeries_The Office - S01E01 - Episode Title")]
|
|
|
|
[TestCase(@"\_UnknownSeries_The Office - S01E01 - Episode Title\")]
|
|
|
|
[TestCase("\\Test\\_UnknownSeries_The Office - S01E01 - Episode Title\\")]
|
|
|
|
[TestCase("\\Test\\_UnknownSeries_The Office - S01E01 - Episode Title")]
|
|
|
|
public void folder_shouldnt_be_tagged_with_same_tag_again(string path)
|
|
|
|
{
|
|
|
|
//Setup
|
2012-01-23 04:59:23 +00:00
|
|
|
|
2011-10-25 04:34:48 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(TempFolder + path);
|
|
|
|
droppedFolder.Create();
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
2011-10-25 04:34:48 +00:00
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null);
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-25 04:34:48 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
2011-10-25 04:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-01-15 03:17:23 +00:00
|
|
|
public void folder_should_not_be_tagged_if_existing_tag_is_diffrent()
|
2011-10-25 04:34:48 +00:00
|
|
|
{
|
|
|
|
//Setup
|
2012-01-23 04:59:23 +00:00
|
|
|
WithOldWrite();
|
2011-10-25 04:34:48 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title");
|
|
|
|
droppedFolder.Create();
|
|
|
|
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
|
|
|
|
|
|
|
|
var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title";
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null);
|
2011-10-25 04:34:48 +00:00
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-25 04:34:48 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2012-01-15 03:17:23 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(droppedFolder.FullName, taggedFolder), Times.Never());
|
|
|
|
ExceptionVerification.IgnoreWarns();
|
2011-10-25 04:34:48 +00:00
|
|
|
}
|
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
[Test]
|
2012-08-09 05:03:42 +00:00
|
|
|
public void when_files_are_imported_and_folder_is_small_enough_dir_should_be_deleted()
|
2011-10-23 02:31:28 +00:00
|
|
|
{
|
|
|
|
//Setup
|
2011-12-15 04:15:53 +00:00
|
|
|
WithStrictMocker();
|
2012-08-09 01:17:44 +00:00
|
|
|
WithLotsOfFreeDiskSpace();
|
|
|
|
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
|
|
|
|
2012-08-09 01:17:44 +00:00
|
|
|
WithImportedFiles(droppedFolder.FullName);
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
2012-04-17 21:44:20 +00:00
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.CleanUpDropFolder(droppedFolder.FullName));
|
2012-07-12 21:08:21 +00:00
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true));
|
2012-10-20 06:46:12 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true);
|
2012-10-20 08:01:47 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.IsFolderLocked(droppedFolder.FullName)).Returns(false);
|
2012-07-12 21:08:21 +00:00
|
|
|
Mocker.GetMock<MetadataProvider>().Setup(s => s.CreateForEpisodeFiles(It.IsAny<List<EpisodeFile>>()));
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void all_imported_files_should_be_moved()
|
|
|
|
{
|
|
|
|
var droppedFolder = new DirectoryInfo(TempFolder);
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<string>())).Returns(fakeSeries);
|
2012-10-20 06:46:12 +00:00
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true);
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
2011-10-23 02:31:28 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true),
|
2011-10-23 02:31:28 +00:00
|
|
|
Times.Exactly(fakeEpisodeFiles.Count));
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
2011-12-10 18:54:16 +00:00
|
|
|
|
|
|
|
[Test]
|
2012-08-29 15:34:51 +00:00
|
|
|
public void should_logError_and_return_if_size_exceeds_free_space()
|
2012-08-09 01:17:44 +00:00
|
|
|
{
|
|
|
|
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
.With(s => s.Path = @"C:\Test\TV\30 Rock")
|
|
|
|
.Build();
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-20 02:05:15 +00:00
|
|
|
.Setup(c => c.GetByTitle("rock"))
|
2012-08-09 01:17:44 +00:00
|
|
|
.Returns(series);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetDirectorySize(downloadName.FullName))
|
|
|
|
.Returns(10);
|
|
|
|
|
2012-10-20 06:46:12 +00:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.FolderExists(series.Path))
|
|
|
|
.Returns(true);
|
|
|
|
|
2012-08-09 01:17:44 +00:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-17 04:33:56 +00:00
|
|
|
.Setup(s => s.FreeDiskSpace(series.Path))
|
2012-08-09 01:17:44 +00:00
|
|
|
.Returns(9);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(series, downloadName.FullName), Times.Never());
|
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-08-29 15:34:51 +00:00
|
|
|
public void should_process_if_free_disk_space_exceeds_size()
|
2012-08-09 01:17:44 +00:00
|
|
|
{
|
|
|
|
WithLotsOfFreeDiskSpace();
|
|
|
|
WithValidSeries();
|
|
|
|
|
|
|
|
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
|
|
|
|
|
|
|
WithImportedFiles(downloadName.FullName);
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-20 02:05:15 +00:00
|
|
|
.Setup(c => c.GetByTitle("rock"))
|
2012-08-09 01:17:44 +00:00
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetDirectorySize(downloadName.FullName))
|
|
|
|
.Returns(8);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(fakeSeries, downloadName.FullName), Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-08-29 15:34:51 +00:00
|
|
|
public void should_process_if_free_disk_space_equals_size()
|
2012-08-09 01:17:44 +00:00
|
|
|
{
|
|
|
|
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
|
|
|
|
|
|
|
WithImportedFiles(downloadName.FullName);
|
|
|
|
WithValidSeries();
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetDirectorySize(downloadName.FullName))
|
|
|
|
.Returns(10);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-17 04:33:56 +00:00
|
|
|
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
|
2012-08-09 01:17:44 +00:00
|
|
|
.Returns(10);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(fakeSeries, downloadName.FullName), Times.Once());
|
|
|
|
}
|
2012-10-20 06:46:12 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_if_series_path_does_not_exist()
|
|
|
|
{
|
|
|
|
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
|
|
|
|
|
|
|
WithValidSeries();
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.FolderExists(fakeSeries.Path))
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectorySize(It.IsAny<String>()), Times.Never());
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
2012-10-20 08:01:47 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_skip_if_folder_is_in_use_by_another_process()
|
|
|
|
{
|
|
|
|
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
|
|
|
|
|
|
|
WithValidSeries();
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.IsFolderLocked(downloadName.FullName))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectorySize(It.IsAny<String>()), Times.Never());
|
|
|
|
}
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
}
|