2011-06-22 07:44:57 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-03-04 00:18:43 +01:00
|
|
|
|
using System.Linq;
|
2011-06-22 07:44:57 +02:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2011-11-13 05:07:06 +01:00
|
|
|
|
using NzbDrone.Common;
|
2013-03-01 08:03:41 +01:00
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2013-02-19 07:01:03 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-06-22 07:44:57 +02:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-07 02:51:47 +01:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-10-24 07:54:09 +02:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 01:22:18 +01:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2012-08-29 17:34:51 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
2011-06-22 07:44:57 +02:00
|
|
|
|
{
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2013-02-17 06:44:06 +01:00
|
|
|
|
public class ImportFileFixture : CoreTest
|
2011-06-22 07:44:57 +02:00
|
|
|
|
{
|
2012-10-14 02:36:16 +02:00
|
|
|
|
public static object[] ImportTestCases =
|
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
new object[] { Quality.SDTV, false },
|
|
|
|
|
new object[] { Quality.DVD, true },
|
|
|
|
|
new object[] { Quality.HDTV720p, false }
|
2012-10-14 02:36:16 +02:00
|
|
|
|
};
|
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
private readonly long SIZE = 80.Megabytes();
|
2013-02-08 02:47:24 +01:00
|
|
|
|
private Series _series;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
_series = Builder<Series>
|
|
|
|
|
.CreateNew()
|
2013-03-24 05:16:00 +01:00
|
|
|
|
.With(s => s.SeriesType = SeriesTypes.Standard)
|
2013-02-08 02:47:24 +01:00
|
|
|
|
.Build();
|
|
|
|
|
}
|
2012-10-20 03:42:42 +02:00
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
public void With80MBFile()
|
2012-10-20 03:42:42 +02:00
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(d => d.GetSize(It.IsAny<String>()))
|
2012-12-31 09:41:19 +01:00
|
|
|
|
.Returns(80.Megabytes());
|
2012-10-20 03:42:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 02:47:24 +01:00
|
|
|
|
public void WithDailySeries()
|
|
|
|
|
{
|
2013-03-24 05:16:00 +01:00
|
|
|
|
_series.SeriesType = SeriesTypes.Daily;
|
2013-02-08 02:47:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void import_new_file_should_succeed()
|
|
|
|
|
{
|
|
|
|
|
const string newFile = @"WEEDS.S03E01.DUAL.dvd.HELLYWOOD.avi";
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-10-20 03:42:42 +02:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 02:36:16 +02:00
|
|
|
|
[Test, TestCaseSource("ImportTestCases")]
|
2013-02-27 04:19:22 +01:00
|
|
|
|
public void import_new_file_with_better_same_quality_should_succeed(Quality currentFileQuality, bool currentFileProper)
|
2011-06-22 07:44:57 +02:00
|
|
|
|
{
|
|
|
|
|
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
2013-04-01 08:22:16 +02:00
|
|
|
|
.With(g => g.Quality = new QualityModel(currentFileQuality, currentFileProper))
|
|
|
|
|
.Build()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
).Build();
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-10-20 03:42:42 +02:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.SDTV.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
public void import_new_file_episode_has_same_or_better_quality_should_skip(string fileName)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
2013-04-01 08:22:16 +02:00
|
|
|
|
.With(e => e.Quality = new QualityModel(Quality.Bluray720p)).Build()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifySkipImport(result, Mocker);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void import_unparsable_file_should_skip()
|
|
|
|
|
{
|
2012-10-20 03:42:42 +02:00
|
|
|
|
const string fileName = @"C:\Test\WEEDS.avi";
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifySkipImport(result, Mocker);
|
2012-02-11 06:42:54 +01:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void import_existing_file_should_skip()
|
|
|
|
|
{
|
|
|
|
|
const string fileName = "WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2012-10-20 03:42:42 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifySkipImport(result, Mocker);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void import_file_with_no_episode_in_db_should_skip()
|
|
|
|
|
{
|
|
|
|
|
//Constants
|
|
|
|
|
const string fileName = "WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2012-10-21 02:19:30 +02:00
|
|
|
|
Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
|
|
|
|
.Setup(e => e.IsChildOfPath(fileName, fakeSeries.Path)).Returns(false);
|
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2012-10-20 03:42:42 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>()))
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
|
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifySkipImport(result, Mocker);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv")]
|
|
|
|
|
public void import_new_file_episode_has_better_quality_than_existing(string fileName)
|
|
|
|
|
{
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
2013-04-01 08:22:16 +02:00
|
|
|
|
.With(e => e.Quality = new QualityModel(Quality.SDTV)).Build()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-10-20 03:42:42 +02:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
2012-09-04 09:31:16 +02:00
|
|
|
|
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv")]
|
|
|
|
|
public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_existing(string fileName)
|
|
|
|
|
{
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
2013-04-01 08:22:16 +02:00
|
|
|
|
.With(f => f.Quality = new QualityModel(Quality.SDTV))
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Build())
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(fakeEpisodes);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-10-20 03:42:42 +02:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisodes[0], SIZE);
|
2012-09-04 09:31:16 +02:00
|
|
|
|
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
[TestCase("WEEDS.S03E01.DUAL.HDTV.XviD.AC3.-HELLYWOOD.avi")]
|
|
|
|
|
public void skip_import_new_multi_part_file_episode_existing_has_better_quality(string fileName)
|
|
|
|
|
{
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
2013-04-01 08:22:16 +02:00
|
|
|
|
.With(f => f.Quality = new QualityModel(Quality.Bluray720p))
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Build())
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Mocks
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(fakeEpisodes);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifySkipImport(result, Mocker);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void import_new_multi_part_file_episode_replace_two_files()
|
|
|
|
|
{
|
|
|
|
|
const string fileName = "WEEDS.S03E01E02.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv";
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
2013-04-01 08:22:16 +02:00
|
|
|
|
.With(e => e.Quality = new QualityModel(Quality.SDTV))
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode1 = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.EpisodeFile = fakeEpisodeFiles[0])
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode2 = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.EpisodeFile = fakeEpisodeFiles[1])
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode1, fakeEpisode2 });
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-10-20 03:42:42 +02:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode1, SIZE);
|
2012-09-04 09:31:16 +02:00
|
|
|
|
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-01-21 01:35:42 +01:00
|
|
|
|
public void should_import_new_episode_no_existing_episode_file()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
{
|
|
|
|
|
const string fileName = "WEEDS.S03E01E02.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv";
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-10-20 03:42:42 +02:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-17 09:39:06 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_set_parseResult_SceneSource_if_not_in_series_Path()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(s => s.Path == @"C:\Test\TV\30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string path = @"C:\Test\Unsorted TV\30 Rock\30.rock.s01e01.pilot.mkv";
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2012-10-21 02:19:30 +02:00
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(s => s.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>()))
|
2012-10-17 09:39:06 +02:00
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.IsChildOfPath(path, series.Path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<DiskScanProvider>().ImportFile(series, path);
|
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
Mocker.Verify<IEpisodeService>(s => s.GetEpisodesByParseResult(It.Is<IndexerParseResult>(p => p.SceneSource)), Times.Once());
|
2012-10-17 09:39:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_set_parseResult_SceneSource_if_in_series_Path()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(s => s.Path == @"C:\Test\TV\30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string path = @"C:\Test\TV\30 Rock\30.rock.s01e01.pilot.mkv";
|
|
|
|
|
|
2012-12-31 09:41:19 +01:00
|
|
|
|
With80MBFile();
|
2012-10-21 02:19:30 +02:00
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(s => s.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>()))
|
2012-10-17 09:39:06 +02:00
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.IsChildOfPath(path, series.Path))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<DiskScanProvider>().ImportFile(series, path);
|
|
|
|
|
|
2013-04-07 21:01:24 +02:00
|
|
|
|
Mocker.Verify<IEpisodeService>(s => s.GetEpisodesByParseResult(It.Is<IndexerParseResult>(p => p.SceneSource == false)), Times.Once());
|
2012-10-17 09:39:06 +02:00
|
|
|
|
}
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
2013-01-26 08:18:42 +01:00
|
|
|
|
public void should_return_null_if_file_size_is_under_70MB_and_runTime_under_3_minutes()
|
2013-01-21 01:35:42 +01:00
|
|
|
|
{
|
|
|
|
|
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2013-01-21 01:35:42 +01:00
|
|
|
|
.Setup(m => m.Exists(path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(d => d.GetSize(path))
|
|
|
|
|
.Returns(20.Megabytes());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaInfoProvider>()
|
|
|
|
|
.Setup(s => s.GetRunTime(path))
|
2013-01-26 08:18:42 +01:00
|
|
|
|
.Returns(60);
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
2013-02-08 02:47:24 +01:00
|
|
|
|
Mocker.Resolve<DiskScanProvider>().ImportFile(_series, path).Should().BeNull();
|
2013-01-21 01:35:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-01-26 08:18:42 +01:00
|
|
|
|
public void should_import_if_file_size_is_under_70MB_but_runTime_over_3_minutes()
|
2013-01-21 01:35:42 +01:00
|
|
|
|
{
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2013-01-21 01:35:42 +01:00
|
|
|
|
.Setup(m => m.Exists(path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(d => d.GetSize(path))
|
|
|
|
|
.Returns(20.Megabytes());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaInfoProvider>()
|
|
|
|
|
.Setup(s => s.GetRunTime(path))
|
|
|
|
|
.Returns(600);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
2013-02-08 02:47:24 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(_series, path);
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, 20.Megabytes());
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-01-26 08:18:42 +01:00
|
|
|
|
public void should_import_if_file_size_is_over_70MB_but_runTime_under_3_minutes()
|
2013-01-21 01:35:42 +01:00
|
|
|
|
{
|
|
|
|
|
With80MBFile();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2013-01-21 01:35:42 +01:00
|
|
|
|
.Setup(m => m.Exists(path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaInfoProvider>()
|
|
|
|
|
.Setup(s => s.GetRunTime(path))
|
2013-01-26 08:18:42 +01:00
|
|
|
|
.Returns(60);
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
2013-02-08 02:47:24 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(_series, path);
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 02:47:24 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_import_special_even_if_file_size_is_under_70MB_and_runTime_under_3_minutes()
|
|
|
|
|
{
|
|
|
|
|
With80MBFile();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
const string path = @"C:\Test\TV\30.rock.s00e01.pre-pilot.avi";
|
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2013-02-08 02:47:24 +01:00
|
|
|
|
.Setup(m => m.Exists(path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(d => d.GetSize(path))
|
|
|
|
|
.Returns(20.Megabytes());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaInfoProvider>()
|
|
|
|
|
.Setup(s => s.GetRunTime(path))
|
|
|
|
|
.Returns(60);
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2013-04-07 21:01:24 +02:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<IndexerParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2013-02-08 02:47:24 +01:00
|
|
|
|
|
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(_series, path);
|
|
|
|
|
|
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, 20.Megabytes());
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_null_if_daily_series_with_file_size_is_under_70MB_and_runTime_under_3_minutes()
|
|
|
|
|
{
|
|
|
|
|
WithDailySeries();
|
|
|
|
|
|
|
|
|
|
const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi";
|
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2013-02-08 02:47:24 +01:00
|
|
|
|
.Setup(m => m.Exists(path))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(d => d.GetSize(path))
|
|
|
|
|
.Returns(20.Megabytes());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaInfoProvider>()
|
|
|
|
|
.Setup(s => s.GetRunTime(path))
|
|
|
|
|
.Returns(60);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<DiskScanProvider>().ImportFile(_series, path).Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 01:35:42 +01:00
|
|
|
|
private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episode fakeEpisode, long size)
|
|
|
|
|
{
|
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
|
result.SeriesId.Should().Be(fakeEpisode.SeriesId);
|
|
|
|
|
result.Size.Should().Be(size);
|
|
|
|
|
result.DateAdded.Should().HaveDay(DateTime.Now.Day);
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
|
|
|
|
//Get the count of episodes linked
|
2013-02-22 01:47:09 +01:00
|
|
|
|
var count = Mocker.GetMock<IEpisodeService>().Object.GetEpisodesByParseResult(null).Count;
|
2013-01-21 01:35:42 +01:00
|
|
|
|
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.Id)), Times.Exactly(count));
|
2013-01-21 01:35:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker)
|
|
|
|
|
{
|
|
|
|
|
result.Should().BeNull();
|
2013-03-01 08:03:41 +01:00
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
2013-01-21 01:35:42 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
|
|
|
|
}
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|