2011-06-22 07:44:57 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-11-14 01:22:18 +01:00
|
|
|
|
|
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;
|
2011-06-22 07:44:57 +02: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;
|
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
|
|
|
|
|
2011-10-21 01:42:17 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-06-22 07:44:57 +02:00
|
|
|
|
{
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 08:27:16 +01:00
|
|
|
|
public class DiskScanProviderTest_ImportFile : CoreTest
|
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
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(QualityTypes.SDTV, false)]
|
|
|
|
|
[TestCase(QualityTypes.DVD, true)]
|
|
|
|
|
[TestCase(QualityTypes.HDTV, false)]
|
|
|
|
|
public void import_new_file_with_better_same_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper)
|
|
|
|
|
{
|
|
|
|
|
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
|
.With(g => g.Quality = (QualityTypes)currentFileQuality)
|
|
|
|
|
.And(g => g.Proper = currentFileProper).Build()
|
|
|
|
|
).Build();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01: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()
|
|
|
|
|
.With(e => e.Quality = QualityTypes.Bluray720p).Build()
|
|
|
|
|
)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
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()
|
|
|
|
|
{
|
|
|
|
|
const string fileName = @"WEEDS.avi";
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
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_sample_file_should_skip()
|
|
|
|
|
{
|
|
|
|
|
const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv";
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifySkipImport(result, Mocker);
|
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();
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
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
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(90000000000);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>()))
|
2011-06-22 07:44:57 +02:00
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
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()
|
|
|
|
|
.With(e => e.Quality = QualityTypes.SDTV).Build()
|
|
|
|
|
)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
|
|
|
|
|
Mocker.GetMock<DiskProvider>().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()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.With(f => f.Quality = QualityTypes.SDTV)
|
|
|
|
|
.Build())
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(fakeEpisodes);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisodes[0], 12345);
|
|
|
|
|
Mocker.GetMock<DiskProvider>().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()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.With(f => f.Quality = QualityTypes.Bluray720p)
|
|
|
|
|
.Build())
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(fakeEpisodes);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
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()
|
|
|
|
|
.With(e => e.Quality = QualityTypes.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
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode1, fakeEpisode2 });
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode1, 12345);
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void import_new_episode_no_existing_episode_file()
|
|
|
|
|
{
|
|
|
|
|
const string fileName = "WEEDS.S03E01E02.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv";
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.EpisodeFileId = 0)
|
|
|
|
|
.With(e => e.EpisodeFile = null)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-08-26 08:23:21 +02:00
|
|
|
|
.Setup(p => p.Exists(It.IsAny<String>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode});
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
2011-08-26 08:23:21 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-15 05:15:53 +01:00
|
|
|
|
VerifyFileImport(result, Mocker, fakeEpisode, 12345);
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
2011-08-26 08:23:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
private static void VerifyFileImport(EpisodeFile result, AutoMoqer Mocker, Episode fakeEpisode, int size)
|
2011-06-22 07:44:57 +02:00
|
|
|
|
{
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-06-22 07:44:57 +02:00
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
|
result.SeriesId.Should().Be(fakeEpisode.SeriesId);
|
|
|
|
|
result.Size.Should().Be(size);
|
|
|
|
|
result.DateAdded.Should().HaveDay(DateTime.Now.Day);
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
|
|
|
|
//Get the count of episodes linked
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var count = Mocker.GetMock<EpisodeProvider>().Object.GetEpisodesByParseResult(null).Count;
|
2011-06-22 07:44:57 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count));
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker)
|
2011-06-22 07:44:57 +02:00
|
|
|
|
{
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-06-22 07:44:57 +02:00
|
|
|
|
result.Should().BeNull();
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
|
|
|
|
Mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
2011-06-22 07:44:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|