2013-07-12 05:57:24 +00:00
|
|
|
using System.Collections.Generic;
|
2014-07-23 23:43:54 +00:00
|
|
|
using System.IO;
|
2013-07-12 05:57:24 +00:00
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2014-09-01 23:37:59 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2013-07-12 05:57:24 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
2013-09-14 06:36:07 +00:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2013-07-12 05:57:24 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Profiles;
|
2013-07-12 05:57:24 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-09-10 17:54:59 +00:00
|
|
|
using NzbDrone.Core.Tv;
|
2013-07-26 06:37:18 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2013-07-12 05:57:24 +00:00
|
|
|
|
2013-09-10 17:54:59 +00:00
|
|
|
namespace NzbDrone.Core.Test.MediaFiles
|
2013-07-12 05:57:24 +00:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class ImportApprovedEpisodesFixture : CoreTest<ImportApprovedEpisodes>
|
|
|
|
{
|
|
|
|
private List<ImportDecision> _rejectedDecisions;
|
|
|
|
private List<ImportDecision> _approvedDecisions;
|
|
|
|
|
2014-09-01 23:37:59 +00:00
|
|
|
private DownloadClientItem _downloadClientItem;
|
|
|
|
|
2013-07-12 05:57:24 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
_rejectedDecisions = new List<ImportDecision>();
|
|
|
|
_approvedDecisions = new List<ImportDecision>();
|
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2014-06-08 08:22:55 +00:00
|
|
|
.With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() })
|
2014-07-23 23:43:54 +00:00
|
|
|
.With(s => s.Path = @"C:\Test\TV\30 Rock".AsOsAgnostic())
|
2013-07-12 05:57:24 +00:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
.Build();
|
|
|
|
|
2014-09-01 23:37:59 +00:00
|
|
|
|
|
|
|
|
2013-07-12 05:57:24 +00:00
|
|
|
_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,
|
2014-09-01 23:37:59 +00:00
|
|
|
Episodes = new List<Episode> { episode },
|
2014-07-23 23:43:54 +00:00
|
|
|
Path = Path.Combine(series.Path, "30 Rock - S01E01 - Pilot.avi"),
|
2013-12-09 06:25:11 +00:00
|
|
|
Quality = new QualityModel(Quality.Bluray720p),
|
|
|
|
ParsedEpisodeInfo = new ParsedEpisodeInfo
|
|
|
|
{
|
|
|
|
ReleaseGroup = "DRONE"
|
|
|
|
}
|
2013-07-12 05:57:24 +00:00
|
|
|
}));
|
|
|
|
}
|
2013-08-12 07:20:36 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IUpgradeMediaFiles>()
|
2014-04-19 15:09:22 +00:00
|
|
|
.Setup(s => s.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<LocalEpisode>(), false))
|
2013-11-18 18:23:36 +00:00
|
|
|
.Returns(new EpisodeFileMoveResult());
|
2014-09-01 23:37:59 +00:00
|
|
|
|
|
|
|
_downloadClientItem = Builder<DownloadClientItem>.CreateNew().Build();
|
2013-07-12 05:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2014-08-22 00:57:23 +00:00
|
|
|
public void should_not_import_any_if_there_are_no_approved_decisions()
|
2013-07-12 05:57:24 +00:00
|
|
|
{
|
2014-08-22 00:57:23 +00:00
|
|
|
Subject.Import(_rejectedDecisions, false).Where(i => i.Result == ImportResultType.Imported).Should().BeEmpty();
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
2013-07-12 05:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_import_each_approved()
|
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
Subject.Import(_approvedDecisions, false).Should().HaveCount(5);
|
2013-07-12 05:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_only_import_approved()
|
|
|
|
{
|
|
|
|
var all = new List<ImportDecision>();
|
|
|
|
all.AddRange(_rejectedDecisions);
|
|
|
|
all.AddRange(_approvedDecisions);
|
|
|
|
|
2014-08-22 00:57:23 +00:00
|
|
|
var result = Subject.Import(all, false);
|
|
|
|
|
|
|
|
result.Should().HaveCount(all.Count);
|
|
|
|
result.Where(i => i.Result == ImportResultType.Imported).Should().HaveCount(_approvedDecisions.Count);
|
2013-07-12 05:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_only_import_each_episode_once()
|
|
|
|
{
|
|
|
|
var all = new List<ImportDecision>();
|
|
|
|
all.AddRange(_approvedDecisions);
|
|
|
|
all.Add(new ImportDecision(_approvedDecisions.First().LocalEpisode));
|
|
|
|
|
2014-08-22 00:57:23 +00:00
|
|
|
var result = Subject.Import(all, false);
|
|
|
|
|
|
|
|
result.Where(i => i.Result == ImportResultType.Imported).Should().HaveCount(_approvedDecisions.Count);
|
2013-07-12 05:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_move_new_downloads()
|
|
|
|
{
|
2014-09-01 23:37:59 +00:00
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
2013-07-12 05:57:24 +00:00
|
|
|
|
2013-07-16 02:56:46 +00:00
|
|
|
Mocker.GetMock<IUpgradeMediaFiles>()
|
2014-04-19 15:09:22 +00:00
|
|
|
.Verify(v => v.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), _approvedDecisions.First().LocalEpisode, false),
|
2013-07-12 05:57:24 +00:00
|
|
|
Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_publish_EpisodeImportedEvent_for_new_downloads()
|
|
|
|
{
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
|
|
|
|
2013-09-14 06:36:07 +00:00
|
|
|
Mocker.GetMock<IEventAggregator>()
|
2013-07-12 05:57:24 +00:00
|
|
|
.Verify(v => v.PublishEvent(It.IsAny<EpisodeImportedEvent>()), Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_move_existing_files()
|
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, false);
|
2013-07-12 05:57:24 +00:00
|
|
|
|
2013-07-16 02:56:46 +00:00
|
|
|
Mocker.GetMock<IUpgradeMediaFiles>()
|
2014-04-19 15:09:22 +00:00
|
|
|
.Verify(v => v.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), _approvedDecisions.First().LocalEpisode, false),
|
2013-07-12 05:57:24 +00:00
|
|
|
Times.Never());
|
|
|
|
}
|
|
|
|
|
2014-09-01 23:37:59 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_use_nzb_title_as_scene_name()
|
|
|
|
{
|
|
|
|
_downloadClientItem.Title = "malcolm.in.the.middle.s02e05.dvdrip.xvid-ingot";
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.SceneName == _downloadClientItem.Title)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_use_nzb_title_as_scene_name_if_full_season()
|
|
|
|
{
|
|
|
|
_approvedDecisions.First().LocalEpisode.Path = "c:\\tv\\season1\\malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv";
|
|
|
|
_downloadClientItem.Title = "malcolm.in.the.middle.s02.dvdrip.xvid-ingot";
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.SceneName == "malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot")));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_use_file_name_as_scenename_only_if_it_looks_like_scenename()
|
|
|
|
{
|
|
|
|
|
|
|
|
_approvedDecisions.First().LocalEpisode.Path = "c:\\tv\\malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv";
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.SceneName == "malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot")));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_use_file_name_as_scenename_if_it_doesnt_looks_like_scenename()
|
|
|
|
{
|
|
|
|
_approvedDecisions.First().LocalEpisode.Path = "c:\\tv\\aaaaa.mkv";
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.SceneName == null)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-12 05:57:24 +00:00
|
|
|
[Test]
|
2013-10-14 16:22:16 +00:00
|
|
|
public void should_import_larger_files_first()
|
|
|
|
{
|
|
|
|
var fileDecision = _approvedDecisions.First();
|
|
|
|
fileDecision.LocalEpisode.Size = 1.Gigabytes();
|
|
|
|
|
|
|
|
var sampleDecision = new ImportDecision
|
|
|
|
(new LocalEpisode
|
|
|
|
{
|
|
|
|
Series = fileDecision.LocalEpisode.Series,
|
2014-09-01 23:37:59 +00:00
|
|
|
Episodes = new List<Episode> { fileDecision.LocalEpisode.Episodes.First() },
|
2014-08-22 00:57:23 +00:00
|
|
|
Path = @"C:\Test\TV\30 Rock\30 Rock - S01E01 - Pilot.avi".AsOsAgnostic(),
|
2013-10-14 16:22:16 +00:00
|
|
|
Quality = new QualityModel(Quality.Bluray720p),
|
|
|
|
Size = 80.Megabytes()
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var all = new List<ImportDecision>();
|
|
|
|
all.Add(fileDecision);
|
|
|
|
all.Add(sampleDecision);
|
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
var results = Subject.Import(all, false);
|
2013-10-14 16:22:16 +00:00
|
|
|
|
2014-08-22 00:57:23 +00:00
|
|
|
results.Should().HaveCount(all.Count);
|
|
|
|
results.Should().ContainSingle(d => d.Result == ImportResultType.Imported);
|
|
|
|
results.Should().ContainSingle(d => d.Result == ImportResultType.Imported && d.ImportDecision.LocalEpisode.Size == fileDecision.LocalEpisode.Size);
|
2013-10-14 16:22:16 +00:00
|
|
|
}
|
2013-07-12 05:57:24 +00:00
|
|
|
}
|
|
|
|
}
|