2013-04-12 23:28:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common;
|
2013-03-01 07:03:41 +00:00
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-03-06 21:20:33 +00:00
|
|
|
|
using NzbDrone.Core.Organizer;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-07 01:51:47 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class CleanUpDropFolderFixture : CoreTest
|
2012-08-29 15:34:51 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_do_nothing_if_no_files_are_found()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
var folder = @"C:\Test\DropDir\The Office";
|
2013-03-06 21:35:39 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
|
|
|
|
|
.Returns(new string[0]);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
Mocker.Resolve<DiskScanProvider>().CleanUpDropFolder(folder);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.GetFileByPath(It.IsAny<string>()), Times.Never());
|
2012-08-29 15:34:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_do_nothing_if_no_conflicting_files_are_found()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
var folder = @"C:\Test\DropDir\The Office";
|
|
|
|
|
var filename = Path.Combine(folder, "NotAProblem.avi");
|
|
|
|
|
|
|
|
|
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
|
.With(f => f.Path = filename.NormalizePath())
|
|
|
|
|
.With(f => f.SeriesId = 12345)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
|
|
|
|
|
.Returns(new string[] { filename });
|
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Setup(s => s.GetFileByPath(filename))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(() => null);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
Mocker.Resolve<DiskScanProvider>().CleanUpDropFolder(folder);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.GetFileByPath(filename), Times.Once());
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>().Verify(v => v.Get(It.IsAny<int>()), Times.Never());
|
2012-08-29 15:34:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_move_file_if_a_conflict_is_found()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
var folder = @"C:\Test\DropDir\The Office";
|
|
|
|
|
var filename = Path.Combine(folder, "Problem.avi");
|
|
|
|
|
var seriesId = 12345;
|
|
|
|
|
var newFilename = "S01E01 - Title";
|
|
|
|
|
var newFilePath = @"C:\Test\TV\The Office\Season 01\S01E01 - Title.avi";
|
|
|
|
|
|
|
|
|
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
|
.With(f => f.Path = filename.NormalizePath())
|
|
|
|
|
.With(f => f.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = seriesId)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(s => s.Title = "The Office")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var episode = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.With(e => e.EpisodeFile = episodeFile)
|
2013-03-03 23:18:43 +00:00
|
|
|
|
.Build().ToList();
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Setup(v => v.GetFileByPath(filename))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(() => null);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
|
|
|
|
|
.Returns(new string[] { filename });
|
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Setup(s => s.GetFileByPath(filename))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(episodeFile);
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.Get(It.IsAny<int>()))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(series);
|
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(s => s.GetEpisodesByFileId(episodeFile.Id))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(episode);
|
|
|
|
|
|
2013-03-06 21:35:39 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>().Setup(s => s.BuildFilename(It.IsAny<IList<Episode>>(), series, It.IsAny<EpisodeFile>()))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(newFilename);
|
|
|
|
|
|
2013-03-06 21:35:39 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>().Setup(s => s.BuildFilePath(It.IsAny<Series>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>()))
|
2013-03-06 22:20:34 +00:00
|
|
|
|
.Returns(newFilePath);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-01-13 23:33:17 +00:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(s => s.FileExists(filename))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveFile(episodeFile.Path, newFilePath));
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
Mocker.Resolve<DiskScanProvider>().CleanUpDropFolder(folder);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.GetFileByPath(filename), Times.Once());
|
2012-08-29 15:34:51 +00:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(v => v.MoveFile(filename.NormalizePath(), newFilePath), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|