2012-08-29 15:34:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common;
|
2013-02-24 19:18:48 +00:00
|
|
|
|
using NzbDrone.Core.Download;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-08-29 15:34:51 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class MoveEpisodeFileFixture : CoreTest
|
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-24 19:57:33 +00:00
|
|
|
|
.With(s => s.OID = 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-24 19:57:33 +00:00
|
|
|
|
.With(e => e.SeriesId = fakeSeries.OID)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string filename = @"30 Rock - S01E01 - TBD";
|
|
|
|
|
var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".avi"));
|
|
|
|
|
|
|
|
|
|
var file = Builder<EpisodeFile>.CreateNew()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.With(f => f.SeriesId = fakeSeries.OID)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(f => f.Path = fi.FullName)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.Setup(e => e.Get(fakeSeries.OID))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
|
|
|
|
|
.Returns(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2012-12-27 03:51:04 +00:00
|
|
|
|
.Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny<QualityTypes>(), It.IsAny<bool>(), It.IsAny<EpisodeFile>()))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(filename);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(e => e.CalculateFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".avi"))
|
|
|
|
|
.Returns(fi);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, false);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_EpisodeFiles_quality()
|
|
|
|
|
{
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.With(s => s.OID = 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-24 19:57:33 +00:00
|
|
|
|
.With(e => e.SeriesId = fakeSeries.OID)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string filename = @"30 Rock - S01E01 - TBD";
|
|
|
|
|
var fi = new FileInfo(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]";
|
|
|
|
|
|
2013-01-13 23:09:44 +00:00
|
|
|
|
var file = Builder<EpisodeFile>.CreateNew()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.With(f => f.SeriesId = fakeSeries.OID)
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.With(f => f.Path = currentFilename)
|
|
|
|
|
.With(f => f.Quality = QualityTypes.WEBDL720p)
|
|
|
|
|
.With(f => f.Proper = false)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.Setup(e => e.Get(fakeSeries.OID))
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
|
|
|
|
|
.Returns(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny<QualityTypes>(), It.IsAny<bool>(), It.IsAny<EpisodeFile>()))
|
|
|
|
|
.Returns(filename);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(e => e.CalculateFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
|
|
|
|
.Returns(fi);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(s => s.FileExists(currentFilename))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
|
.Setup(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny<Series>()));
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, true);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
|
.Verify(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny<Series>()), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_log_error_and_return_null_when_source_file_does_not_exists()
|
|
|
|
|
{
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.With(s => s.OID = 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-24 19:57:33 +00:00
|
|
|
|
.With(e => e.SeriesId = fakeSeries.OID)
|
2013-01-13 23:09:44 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string filename = @"30 Rock - S01E01 - TBD";
|
|
|
|
|
var fi = new FileInfo(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]";
|
|
|
|
|
|
2012-08-29 15:34:51 +00:00
|
|
|
|
var file = Builder<EpisodeFile>.CreateNew()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.With(f => f.SeriesId = fakeSeries.OID)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(f => f.Path = currentFilename)
|
2012-10-15 04:30:07 +00:00
|
|
|
|
.With(f => f.Quality = QualityTypes.WEBDL720p)
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.With(f => f.Proper = false)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-24 19:57:33 +00:00
|
|
|
|
.Setup(e => e.Get(fakeSeries.OID))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
|
|
|
|
|
.Returns(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2012-12-27 03:51:04 +00:00
|
|
|
|
.Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny<QualityTypes>(), It.IsAny<bool>(), It.IsAny<EpisodeFile>()))
|
2012-08-29 15:34:51 +00:00
|
|
|
|
.Returns(filename);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(e => e.CalculateFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
|
|
|
|
.Returns(fi);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
|
.Setup(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny<Series>()));
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().MoveEpisodeFile(file, true);
|
|
|
|
|
|
|
|
|
|
//Assert
|
2013-01-13 23:09:44 +00:00
|
|
|
|
result.Should().BeNull();
|
|
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
2012-08-29 15:34:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|