Added tests for ImportApprovedEpisodes

pull/3113/head
Mark McDowall 11 years ago
parent 9b80478f6f
commit 3e7ef408ee

@ -13,7 +13,7 @@ using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
namespace NzbDrone.Core.Test.MediaFileTests
{
[TestFixture]
public class DropFolderImportServiceFixture : CoreTest<DownloadedEpisodesImportService>

@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Common.Messaging;
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.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.MediaFileTests
{
[TestFixture]
public class ImportApprovedEpisodesFixture : CoreTest<ImportApprovedEpisodes>
{
private List<ImportDecision> _rejectedDecisions;
private List<ImportDecision> _approvedDecisions;
[SetUp]
public void Setup()
{
_rejectedDecisions = new List<ImportDecision>();
_approvedDecisions = new List<ImportDecision>();
var series = Builder<Series>.CreateNew()
.Build();
var episodes = Builder<Episode>.CreateListOfSize(5)
.Build();
_rejectedDecisions.Add(new ImportDecision(new LocalEpisode(), "Rejected!"));
_rejectedDecisions.Add(new ImportDecision(new LocalEpisode(), "Rejected!"));
_rejectedDecisions.Add(new ImportDecision(new LocalEpisode(), "Rejected!"));
foreach (var episode in episodes)
{
_approvedDecisions.Add(new ImportDecision
(
new LocalEpisode
{
Series = series,
Episodes = new List<Episode> {episode},
Path = @"C:\Test\TV\30 Rock\30 Rock - S01E01 - Pilit.avi",
Quality = new QualityModel(Quality.Bluray720p)
}));
}
}
[Test]
public void should_return_empty_list_if_there_are_no_approved_decisions()
{
Subject.Import(_rejectedDecisions).Should().BeEmpty();
}
[Test]
public void should_import_each_approved()
{
Subject.Import(_approvedDecisions).Should().HaveCount(5);
}
[Test]
public void should_only_import_approved()
{
var all = new List<ImportDecision>();
all.AddRange(_rejectedDecisions);
all.AddRange(_approvedDecisions);
Subject.Import(all).Should().HaveCount(5);
}
[Test]
public void should_only_import_each_episode_once()
{
var all = new List<ImportDecision>();
all.AddRange(_approvedDecisions);
all.Add(new ImportDecision(_approvedDecisions.First().LocalEpisode));
Subject.Import(all).Should().HaveCount(5);
}
[Test]
public void should_move_new_downloads()
{
Subject.Import(new List<ImportDecision> {_approvedDecisions.First()}, true);
Mocker.GetMock<IMoveEpisodeFiles>()
.Verify(v => v.MoveEpisodeFile(It.IsAny<EpisodeFile>(), _approvedDecisions.First().LocalEpisode),
Times.Once());
}
[Test]
public void should_publish_EpisodeImportedEvent_for_new_downloads()
{
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
Mocker.GetMock<IMessageAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<EpisodeImportedEvent>()), Times.Once());
}
[Test]
public void should_not_move_existing_files()
{
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() });
Mocker.GetMock<IMoveEpisodeFiles>()
.Verify(v => v.MoveEpisodeFile(It.IsAny<EpisodeFile>(), _approvedDecisions.First().LocalEpisode),
Times.Never());
}
[Test]
public void should_not_trigger_EpisodeImportedEvent_for_existing_files()
{
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() });
Mocker.GetMock<IMessageAggregator>()
.Verify(v => v.PublishEvent(It.IsAny<EpisodeImportedEvent>()), Times.Never());
}
}
}

@ -147,6 +147,7 @@
<Compile Include="JobTests\TestJobs.cs" />
<Compile Include="MediaCoverTests\CoverExistsSpecificationFixture.cs" />
<Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" />
<Compile Include="MediaFileTests\ImportApprovedEpisodesFixture.cs" />
<Compile Include="MediaFileTests\EpisodeImportTests\UpgradeSpecificationFixture.cs" />
<Compile Include="MediaFileTests\EpisodeImportTests\NotSampleSpecificationFixture.cs" />
<Compile Include="MediaFileTests\EpisodeImportTests\ImportDecisionMakerFixture.cs" />
@ -193,7 +194,7 @@
<Compile Include="ProviderTests\DiskProviderTests\FreeDiskSpaceTest.cs" />
<Compile Include="NotificationTests\ProwlProviderTest.cs" />
<Compile Include="ProviderTests\DiskProviderTests\ExtractArchiveFixture.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\DropFolderImportServiceFixture.cs" />
<Compile Include="MediaFileTests\DropFolderImportServiceFixture.cs" />
<Compile Include="SeriesStatsTests\SeriesStatisticsFixture.cs" />
<Compile Include="TvTests\SeriesRepositoryTests\QualityProfileRepositoryFixture.cs" />
<Compile Include="UpdateTests\UpdateServiceFixture.cs" />

@ -48,7 +48,7 @@ namespace NzbDrone.Core.MediaFiles
if (!_diskProvider.FolderExists(series.Path))
{
Logger.Trace("Series folder doesn't exist: {0}", series.Path);
Logger.Debug("Series folder doesn't exist: {0}", series.Path);
return;
}

@ -18,14 +18,14 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
public class ImportApprovedEpisodes : IImportApprovedEpisodes
{
private readonly IMoveEpisodeFiles _episodeFileMover;
private readonly MediaFileService _mediaFileService;
private readonly DiskProvider _diskProvider;
private readonly IMediaFileService _mediaFileService;
private readonly IDiskProvider _diskProvider;
private readonly IMessageAggregator _messageAggregator;
private readonly Logger _logger;
public ImportApprovedEpisodes(IMoveEpisodeFiles episodeFileMover,
MediaFileService mediaFileService,
DiskProvider diskProvider,
IMediaFileService mediaFileService,
IDiskProvider diskProvider,
IMessageAggregator messageAggregator,
Logger logger)
{
@ -38,12 +38,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
public List<ImportDecision> Import(List<ImportDecision> decisions, bool newDownload = false)
{
var qualifiedReports = GetQualifiedReports(decisions);
var qualifiedImports = GetQualifiedImports(decisions);
var imported = new List<ImportDecision>();
foreach (var report in qualifiedReports)
foreach (var importDecision in qualifiedImports)
{
var localEpisode = report.LocalEpisode;
var localEpisode = importDecision.LocalEpisode;
try
{
@ -73,6 +73,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
}
_mediaFileService.Add(episodeFile);
imported.Add(importDecision);
}
catch (Exception e)
{
@ -83,7 +84,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
return imported;
}
private List<ImportDecision> GetQualifiedReports(List<ImportDecision> decisions)
private List<ImportDecision> GetQualifiedImports(List<ImportDecision> decisions)
{
return decisions.Where(c => c.Approved)
.OrderByDescending(c => c.LocalEpisode.Quality)

Loading…
Cancel
Save