1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs

165 lines
6.1 KiB
C#
Raw Normal View History

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