2013-03-07 04:49:00 +00:00
|
|
|
|
using System.IO;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
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-27 03:19:22 +00:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-03-07 04:49:00 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
2013-03-07 04:49:00 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.MediaFileTests
|
2012-08-29 15:34:51 +00:00
|
|
|
|
{
|
2013-03-07 04:49:00 +00:00
|
|
|
|
public class EpisodeFileMoverFixture : CoreTest<MoveEpisodeFiles>
|
2012-08-29 15:34:51 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_move_file_if_source_and_destination_are_the_same_path()
|
|
|
|
|
{
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 5)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(e => e.SeriesId = fakeSeries.Id)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
2013-03-03 23:18:43 +00:00
|
|
|
|
.Build().ToList();
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
|
|
|
|
const string filename = @"30 Rock - S01E01 - TBD";
|
2013-07-26 05:41:38 +00:00
|
|
|
|
var fi = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".avi").AsOsAgnostic();
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
|
|
|
|
var file = Builder<EpisodeFile>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(f => f.SeriesId = fakeSeries.Id)
|
2013-03-06 22:20:34 +00:00
|
|
|
|
.With(f => f.Path = fi)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-07-06 22:39:04 +00:00
|
|
|
|
.Setup(e => e.Get(fakeSeries.Id))
|
|
|
|
|
.Returns(fakeSeries);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-07-06 22:39:04 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(file.Id))
|
|
|
|
|
.Returns(fakeEpisode);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-03-06 21:20:33 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-07-06 22:39:04 +00:00
|
|
|
|
.Setup(e => e.BuildFilename(fakeEpisode, fakeSeries, It.IsAny<EpisodeFile>()))
|
|
|
|
|
.Returns(filename);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-03-06 21:20:33 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-07-06 22:39:04 +00:00
|
|
|
|
.Setup(e => e.BuildFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".avi"))
|
|
|
|
|
.Returns(fi);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.FileExists(fi))
|
|
|
|
|
.Returns(true);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-07-06 21:47:49 +00:00
|
|
|
|
var result = Subject.MoveEpisodeFile(file);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
|
|
|
|
result.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_EpisodeFiles_quality()
|
|
|
|
|
{
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 5)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(e => e.SeriesId = fakeSeries.Id)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
2013-03-03 23:18:43 +00:00
|
|
|
|
.Build().ToList();
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
|
|
|
|
const string filename = @"30 Rock - S01E01 - TBD";
|
2013-07-26 05:41:38 +00:00
|
|
|
|
var fi = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv").AsOsAgnostic();
|
|
|
|
|
var currentFilename = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", "30.Rock.S01E01.Test.WED-DL.mkv").AsOsAgnostic();
|
2012-08-29 15:34:51 +00:00
|
|
|
|
const string message = "30 Rock - 1x01 - [WEBDL]";
|
|
|
|
|
|
2013-01-13 23:09:44 +00:00
|
|
|
|
var file = Builder<EpisodeFile>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(f => f.SeriesId = fakeSeries.Id)
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.With(f => f.Path = currentFilename)
|
2013-04-01 06:22:16 +00:00
|
|
|
|
.With(f => f.Quality = new QualityModel(Quality.WEBDL720p))
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.Setup(e => e.Get(fakeSeries.Id))
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-03-01 07:03:41 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(file.Id))
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Returns(fakeEpisode);
|
|
|
|
|
|
2013-03-06 21:20:33 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 21:35:39 +00:00
|
|
|
|
.Setup(e => e.BuildFilename(fakeEpisode, fakeSeries, It.IsAny<EpisodeFile>()))
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Returns(filename);
|
|
|
|
|
|
2013-03-06 21:20:33 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 21:35:39 +00:00
|
|
|
|
.Setup(e => e.BuildFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Returns(fi);
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Setup(s => s.FileExists(currentFilename))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
2013-07-06 21:47:49 +00:00
|
|
|
|
var result = Subject.MoveEpisodeFile(file);
|
2013-01-13 23:09:44 +00:00
|
|
|
|
|
2013-02-24 23:47:57 +00:00
|
|
|
|
|
2013-01-13 23:09:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_log_error_and_return_null_when_source_file_does_not_exists()
|
|
|
|
|
{
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 5)
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
|
.All()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(e => e.SeriesId = fakeSeries.Id)
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
2013-03-03 23:18:43 +00:00
|
|
|
|
.Build().ToList();
|
2013-01-13 23:09:44 +00:00
|
|
|
|
|
|
|
|
|
const string filename = @"30 Rock - S01E01 - TBD";
|
2013-07-26 05:41:38 +00:00
|
|
|
|
var fi = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv").AsOsAgnostic();
|
|
|
|
|
var currentFilename = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", "30.Rock.S01E01.Test.WED-DL.mkv").AsOsAgnostic();
|
2013-01-13 23:09:44 +00:00
|
|
|
|
const string message = "30 Rock - 1x01 - [WEBDL]";
|
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
var file = Builder<EpisodeFile>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(f => f.SeriesId = fakeSeries.Id)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(f => f.Path = currentFilename)
|
2013-04-01 06:22:16 +00:00
|
|
|
|
.With(f => f.Quality = new QualityModel(Quality.WEBDL720p))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.Setup(e => e.Get(fakeSeries.Id))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-03-01 07:03:41 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(file.Id))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(fakeEpisode);
|
|
|
|
|
|
2013-03-06 21:20:33 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 21:35:39 +00:00
|
|
|
|
.Setup(e => e.BuildFilename(fakeEpisode, fakeSeries, It.IsAny<EpisodeFile>()))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(filename);
|
|
|
|
|
|
2013-03-06 21:20:33 +00:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 21:35:39 +00:00
|
|
|
|
.Setup(e => e.BuildFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(fi);
|
|
|
|
|
|
2013-07-06 21:47:49 +00:00
|
|
|
|
var result = Subject.MoveEpisodeFile(file);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
|
2013-01-13 23:09:44 +00:00
|
|
|
|
result.Should().BeNull();
|
|
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|