mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
Episode import uses specs and moves before import now
This commit is contained in:
@@ -199,7 +199,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_unknown_series_rejection_if_series_is_unknow()
|
||||
public void should_return_unknown_series_rejection_if_series_is_unknown()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
|
||||
.Setup(e => e.BuildFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".avi"))
|
||||
.Returns(fi);
|
||||
|
||||
var result = Subject.MoveEpisodeFile(file, false);
|
||||
var result = Subject.MoveEpisodeFile(file);
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
|
||||
.Setup(s => s.FileExists(currentFilename))
|
||||
.Returns(true);
|
||||
|
||||
var result = Subject.MoveEpisodeFile(file, true);
|
||||
var result = Subject.MoveEpisodeFile(file);
|
||||
|
||||
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
|
||||
.Setup(e => e.BuildFilePath(It.IsAny<Series>(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
|
||||
.Returns(fi);
|
||||
|
||||
var result = Subject.MoveEpisodeFile(file, true);
|
||||
var result = Subject.MoveEpisodeFile(file);
|
||||
|
||||
result.Should().BeNull();
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImportDecisionMakerFixture : CoreTest<ImportDecisionMaker>
|
||||
{
|
||||
private List<String> _videoFiles;
|
||||
private LocalEpisode _localEpisode;
|
||||
private Series _series;
|
||||
|
||||
private Mock<IImportDecisionEngineSpecification> _pass1;
|
||||
private Mock<IImportDecisionEngineSpecification> _pass2;
|
||||
private Mock<IImportDecisionEngineSpecification> _pass3;
|
||||
|
||||
private Mock<IImportDecisionEngineSpecification> _fail1;
|
||||
private Mock<IImportDecisionEngineSpecification> _fail2;
|
||||
private Mock<IImportDecisionEngineSpecification> _fail3;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_pass1 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_pass2 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_pass3 = new Mock<IImportDecisionEngineSpecification>();
|
||||
|
||||
_fail1 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_fail2 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_fail3 = new Mock<IImportDecisionEngineSpecification>();
|
||||
|
||||
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
||||
_pass1.Setup(c => c.RejectionReason).Returns("_pass1");
|
||||
|
||||
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
||||
_pass2.Setup(c => c.RejectionReason).Returns("_pass2");
|
||||
|
||||
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
||||
_pass3.Setup(c => c.RejectionReason).Returns("_pass3");
|
||||
|
||||
|
||||
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
||||
_fail1.Setup(c => c.RejectionReason).Returns("_fail1");
|
||||
|
||||
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
||||
_fail2.Setup(c => c.RejectionReason).Returns("_fail2");
|
||||
|
||||
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
||||
_fail3.Setup(c => c.RejectionReason).Returns("_fail3");
|
||||
|
||||
_videoFiles = new List<String> { "The.Office.S03E115.DVDRip.XviD-OSiTV" };
|
||||
_series = new Series();
|
||||
_localEpisode = new LocalEpisode { Series = _series, Path = @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi" };
|
||||
|
||||
Mocker.GetMock<IParsingService>().Setup(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>()))
|
||||
.Returns(_localEpisode);
|
||||
|
||||
}
|
||||
|
||||
private void GivenSpecifications(params Mock<IImportDecisionEngineSpecification>[] mocks)
|
||||
{
|
||||
Mocker.SetConstant<IEnumerable<IRejectWithReason>>(mocks.Select(c => c.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_all_specifications()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
Subject.GetImportDecisions(_videoFiles, new Series());
|
||||
|
||||
_fail1.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_fail2.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_fail3.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_single_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_fail1);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
||||
|
||||
result.Single().Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_one_of_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
||||
|
||||
result.Single().Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_pass_if_all_specs_pass()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
||||
|
||||
result.Single().Approved.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
||||
result.Single().Rejections.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void failed_parse_shouldnt_blowup_the_process()
|
||||
{
|
||||
GivenSpecifications(_pass1);
|
||||
|
||||
Mocker.GetMock<IParsingService>().Setup(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>()))
|
||||
.Throws<TestException>();
|
||||
|
||||
_videoFiles = new List<String>
|
||||
{
|
||||
"The.Office.S03E115.DVDRip.XviD-OSiTV",
|
||||
"The.Office.S03E115.DVDRip.XviD-OSiTV",
|
||||
"The.Office.S03E115.DVDRip.XviD-OSiTV"
|
||||
};
|
||||
|
||||
Subject.GetImportDecisions(_videoFiles, new Series());
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>()), Times.Exactly(_videoFiles.Count));
|
||||
|
||||
ExceptionVerification.ExpectedErrors(3);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotAlreadyImportedSpecificationFixture : CoreTest<NotAlreadyImportedSpecification>
|
||||
{
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi"
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_path_is_already_in_episodeFiles()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.Exists(_localEpisode.Path))
|
||||
.Returns(true);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_new_file()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.Exists(_localEpisode.Path))
|
||||
.Returns(false);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotSampleSpecificationFixture : CoreTest<NotSampleSpecification>
|
||||
{
|
||||
private Series _series;
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesType = SeriesTypes.Standard)
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
||||
Episodes = episodes,
|
||||
Series = _series
|
||||
};
|
||||
}
|
||||
|
||||
private void WithDailySeries()
|
||||
{
|
||||
_series.SeriesType = SeriesTypes.Daily;
|
||||
}
|
||||
|
||||
private void WithSeasonZero()
|
||||
{
|
||||
_localEpisode.Episodes[0].SeasonNumber = 0;
|
||||
}
|
||||
|
||||
private void WithFileSize(long size)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetFileSize(It.IsAny<String>()))
|
||||
.Returns(size);
|
||||
}
|
||||
|
||||
private void WithLength(int minutes)
|
||||
{
|
||||
Mocker.GetMock<IVideoFileInfoReader>()
|
||||
.Setup(s => s.GetRunTime(It.IsAny<String>()))
|
||||
.Returns(new TimeSpan(0, 0, minutes, 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_series_is_daily()
|
||||
{
|
||||
WithDailySeries();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_season_zero()
|
||||
{
|
||||
WithSeasonZero();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_undersize_and_under_length()
|
||||
{
|
||||
WithFileSize(10.Megabytes());
|
||||
WithLength(1);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_undersize()
|
||||
{
|
||||
WithFileSize(10.Megabytes());
|
||||
WithLength(10);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_under_length()
|
||||
{
|
||||
WithFileSize(100.Megabytes());
|
||||
WithLength(1);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_over_size_and_length()
|
||||
{
|
||||
WithFileSize(100.Megabytes());
|
||||
WithLength(10);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Marr.Data;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpgradeSpecificationFixture : CoreTest<UpgradeSpecification>
|
||||
{
|
||||
private Series _series;
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesType = SeriesTypes.Standard)
|
||||
.Build();
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
||||
Quality = new QualityModel(Quality.HDTV720p, false)
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_no_existing_episodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 0)
|
||||
.With(e => e.EpisodeFile = null)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_no_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 0)
|
||||
.With(e => e.EpisodeFile = null)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_upgrade_for_existing_episodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.SDTV, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_upgrade_for_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.SDTV, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.Bluray720p, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.Bluray720p, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_one_existing_episodeFile_for_multi_episode()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.SDTV, false)
|
||||
}))
|
||||
.TheNext(1)
|
||||
.With(e => e.EpisodeFileId = 2)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.Bluray720p, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,6 +148,10 @@
|
||||
<Compile Include="JobTests\TestJobs.cs" />
|
||||
<Compile Include="MediaCoverTests\CoverExistsSpecificationFixture.cs" />
|
||||
<Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\UpgradeSpecificationFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\NotSampleSpecificationFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\ImportDecisionMakerFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\NotAlreadyImportedSpecificationFixture.cs" />
|
||||
<Compile Include="MediaFileTests\MediaFileTableCleanupServiceFixture.cs" />
|
||||
<Compile Include="MediaFileTests\MediaFileRepositoryFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeFileMoverFixture.cs" />
|
||||
@@ -200,7 +204,6 @@
|
||||
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
||||
<Compile Include="Qualities\QualitySizeServiceFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||
<Compile Include="ProviderTests\DiskScanProviderTests\ImportFileFixture.cs" />
|
||||
<Compile Include="FluentTest.cs" />
|
||||
<Compile Include="InstrumentationTests\DatabaseTargetFixture.cs" />
|
||||
<Compile Include="OrganizerTests\GetNewFilenameFixture.cs" />
|
||||
|
||||
@@ -1,303 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
||||
{
|
||||
|
||||
public class ImportFileFixture : CoreTest<DiskScanService>
|
||||
{
|
||||
|
||||
|
||||
private long _fileSize = 80.Megabytes();
|
||||
private Series _fakeSeries;
|
||||
private Episode[] _fakeEpisodes;
|
||||
private Episode _fakeEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_fakeSeries = Builder<Series>
|
||||
.CreateNew()
|
||||
.Build();
|
||||
|
||||
_fakeEpisode = Builder<Episode>
|
||||
.CreateNew()
|
||||
.With(c => c.EpisodeFileId = 0)
|
||||
.Build();
|
||||
|
||||
|
||||
_fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(c => c.SeasonNumber = 3)
|
||||
.With(c => c.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new EpisodeFile())
|
||||
.BuildList().ToArray();
|
||||
|
||||
GivenNewFile();
|
||||
|
||||
GivenVideoDuration(TimeSpan.FromMinutes(20));
|
||||
|
||||
GivenFileSize(_fileSize);
|
||||
|
||||
}
|
||||
|
||||
private void GivenFileSize(long size)
|
||||
{
|
||||
_fileSize = size;
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(d => d.GetFileSize(It.IsAny<String>()))
|
||||
.Returns(size);
|
||||
}
|
||||
|
||||
private void GivenVideoDuration(TimeSpan duration)
|
||||
{
|
||||
Mocker.GetMock<IVideoFileInfoReader>()
|
||||
.Setup(d => d.GetRunTime(It.IsAny<String>()))
|
||||
.Returns(duration);
|
||||
}
|
||||
|
||||
|
||||
private void GivenEpisodes(Episode[] episodes, QualityModel quality)
|
||||
{
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
if (episode.EpisodeFile == null)
|
||||
{
|
||||
episode.EpisodeFileId = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
episode.EpisodeFileId = episode.EpisodeFile.Value.Id;
|
||||
}
|
||||
}
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(c => c.GetEpisodes(It.IsAny<string>(), It.IsAny<Series>()))
|
||||
.Returns(new LocalEpisode
|
||||
{
|
||||
Episodes = episodes.ToList(),
|
||||
Quality = quality
|
||||
});
|
||||
}
|
||||
|
||||
private void GivenNewFile()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_new_file_should_succeed()
|
||||
{
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel());
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
VerifyFileImport(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void import_new_file_with_same_quality_should_succeed()
|
||||
{
|
||||
_fakeEpisode.EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.SDTV) };
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.SDTV));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
VerifyFileImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_new_file_with_better_quality_should_succeed()
|
||||
{
|
||||
_fakeEpisode.EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.SDTV) };
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
VerifyFileImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_new_file_episode_has_better_quality_should_skip()
|
||||
{
|
||||
_fakeEpisode.EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV1080p), Id = 1 };
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.SDTV));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void import_unparsable_file_should_skip()
|
||||
{
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(c => c.GetEpisodes(It.IsAny<string>(), It.IsAny<Series>()))
|
||||
.Returns<LocalEpisode>(null);
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_existing_file_should_skip()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_file_with_no_episode_in_db_should_skip()
|
||||
{
|
||||
GivenEpisodes(new Episode[0], new QualityModel());
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_new_multi_part_file_episode_with_better_quality_than_existing()
|
||||
{
|
||||
_fakeEpisodes[0].EpisodeFile = new EpisodeFile();
|
||||
_fakeEpisodes[1].EpisodeFile = new EpisodeFile();
|
||||
|
||||
_fakeEpisodes[0].EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.SDTV) };
|
||||
_fakeEpisodes[1].EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.SDTV) };
|
||||
|
||||
GivenEpisodes(_fakeEpisodes, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
|
||||
VerifyFileImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void skip_import_new_multi_part_file_episode_existing_has_better_quality()
|
||||
{
|
||||
_fakeEpisodes[0].EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV1080p), Id = 1 };
|
||||
_fakeEpisodes[1].EpisodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV1080p), Id = 1 };
|
||||
|
||||
GivenEpisodes(_fakeEpisodes, new QualityModel(Quality.SDTV));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_file_size_is_under_70MB_and_runTime_under_3_minutes()
|
||||
{
|
||||
GivenFileSize(50.Megabytes());
|
||||
GivenVideoDuration(TimeSpan.FromMinutes(1));
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_if_file_size_is_under_70MB_but_runTime_over_3_minutes()
|
||||
{
|
||||
GivenFileSize(50.Megabytes());
|
||||
GivenVideoDuration(TimeSpan.FromMinutes(20));
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifyFileImport(result);
|
||||
Mocker.GetMock<IDiskProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_if_file_size_is_over_70MB_but_runTime_under_3_minutes()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
GivenVideoDuration(TimeSpan.FromMinutes(1));
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifyFileImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_special_even_if_file_size_is_under_70MB_and_runTime_under_3_minutes()
|
||||
{
|
||||
GivenFileSize(10.Megabytes());
|
||||
GivenVideoDuration(TimeSpan.FromMinutes(1));
|
||||
|
||||
_fakeEpisode.SeasonNumber = 0;
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifyFileImport(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_daily_series_with_file_size_is_under_70MB_and_runTime_under_3_minutes()
|
||||
{
|
||||
GivenFileSize(10.Megabytes());
|
||||
GivenVideoDuration(TimeSpan.FromMinutes(1));
|
||||
|
||||
_fakeEpisode.SeasonNumber = 0;
|
||||
_fakeSeries.SeriesType = SeriesTypes.Daily;
|
||||
|
||||
GivenEpisodes(new[] { _fakeEpisode }, new QualityModel(Quality.HDTV1080p));
|
||||
|
||||
var result = Subject.ImportFile(_fakeSeries, "file.ext");
|
||||
|
||||
VerifySkipImport(result);
|
||||
}
|
||||
|
||||
private void VerifyFileImport(EpisodeFile result)
|
||||
{
|
||||
result.Should().NotBeNull();
|
||||
result.SeriesId.Should().Be(_fakeSeries.Id);
|
||||
result.Size.Should().Be(_fileSize);
|
||||
result.DateAdded.Should().HaveDay(DateTime.UtcNow.Day);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(c => c.Add(result), Times.Once());
|
||||
}
|
||||
|
||||
private void VerifySkipImport(EpisodeFile result)
|
||||
{
|
||||
result.Should().BeNull();
|
||||
Mocker.GetMock<IMediaFileService>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-73
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
@@ -6,6 +7,7 @@ using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Tv;
|
||||
@@ -26,7 +28,6 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
{
|
||||
_fakeEpisodeFile = Builder<EpisodeFile>.CreateNew().Build();
|
||||
|
||||
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
@@ -37,24 +38,6 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
.Returns("c:\\drop\\");
|
||||
}
|
||||
|
||||
private void WithOldWrite()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.Now.AddDays(-5));
|
||||
}
|
||||
|
||||
private void WithRecentFolderWrite()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetLastFileWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_file()
|
||||
{
|
||||
@@ -66,65 +49,14 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
[Test]
|
||||
public void should_search_for_series_using_folder_name()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
Subject.ProcessDownloadedEpisodesFolder();
|
||||
|
||||
Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void all_imported_files_should_be_moved()
|
||||
public void should_skip_if_file_is_in_use_by_another_process()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns(_fakeEpisodeFile);
|
||||
|
||||
Subject.ProcessDownloadedEpisodesFolder();
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(_fakeEpisodeFile, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_trigger_import_event_on_import()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns(_fakeEpisodeFile);
|
||||
|
||||
Subject.ProcessDownloadedEpisodesFolder();
|
||||
|
||||
VerifyEventPublished<EpisodeImportedEvent>();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_attempt_move_if_nothing_is_imported()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns<EpisodeFile>(null);
|
||||
|
||||
Subject.ProcessDownloadedEpisodesFolder();
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<bool>()), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_not_publish_import_event_if_nothing_is_imported()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns<EpisodeFile>(null);
|
||||
|
||||
Subject.ProcessDownloadedEpisodesFolder();
|
||||
|
||||
|
||||
VerifyEventNotPublished<EpisodeImportedEvent>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_folder_is_in_use_by_another_process()
|
||||
{
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(true);
|
||||
|
||||
@@ -134,13 +66,13 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
|
||||
private void VerifyNoImport()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()),
|
||||
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
private void VerifyImport()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()),
|
||||
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true),
|
||||
Times.Once());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user