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;
|
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]
|
2011-12-10 18:54:16 +00:00
|
|
|
public class ProcessDownloadProviderFixture : CoreTest
|
2011-10-23 02:31:28 +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);
|
|
|
|
}
|
|
|
|
|
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
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null).Verifiable();
|
|
|
|
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");
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("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
|
|
|
}
|
|
|
|
|
|
|
|
[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
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns<Series>(null);
|
|
|
|
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
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
|
|
|
|
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
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
|
|
|
|
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);
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true);
|
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
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<String>())).Returns<Series>(null);
|
|
|
|
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";
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(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]
|
|
|
|
public void when_files_are_imported_and_folder_is_small_enought_dir_should_be_deleted()
|
|
|
|
{
|
|
|
|
//Setup
|
2011-12-15 04:15:53 +00:00
|
|
|
WithStrictMocker();
|
2011-10-23 02:31:28 +00:00
|
|
|
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("office")).Returns(fakeSeries);
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(true);
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true));
|
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();
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<string>())).Returns(fakeSeries);
|
|
|
|
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]
|
|
|
|
public void ProcessDropFolder_should_only_process_folders_that_arent_known_series_folders()
|
|
|
|
{
|
|
|
|
var subFolders = new List<string>
|
|
|
|
{
|
|
|
|
@"c:\drop\episode1",
|
|
|
|
@"c:\drop\episode2",
|
|
|
|
@"c:\drop\episode3",
|
|
|
|
@"c:\drop\episode4"
|
|
|
|
};
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(c => c.GetDirectories(It.IsAny<String>()))
|
|
|
|
.Returns(subFolders);
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
.Setup(c => c.SeriesPathExists(subFolders[1]))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
.Setup(c => c.FindSeries(It.IsAny<String>()))
|
|
|
|
.Returns(new Series());
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskScanProvider>()
|
|
|
|
.Setup(c => c.Scan(It.IsAny<Series>(), It.IsAny<String>()))
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
|
|
//Act
|
|
|
|
Mocker.Resolve<PostDownloadProvider>().ProcessDropFolder(@"C:\drop\");
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[0]), Times.Once());
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[1]), Times.Never());
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[2]), Times.Once());
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[3]), Times.Once());
|
|
|
|
}
|
2011-10-23 02:31:28 +00:00
|
|
|
}
|
|
|
|
}
|