2011-10-21 01:42:17 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-03-04 00:18:43 +01:00
|
|
|
|
using System.Linq;
|
2011-09-04 05:05:44 +02:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-03-01 08:03:41 +01:00
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-03-06 22:20:33 +01:00
|
|
|
|
using NzbDrone.Core.Organizer;
|
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-09-04 05:05:44 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-07 02:51:47 +01:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 01:22:18 +01:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2011-10-21 01:42:17 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-09-04 05:05:44 +02:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-02-17 06:44:06 +01:00
|
|
|
|
public class MisnamedProviderTest : CoreTest
|
2011-09-04 05:05:44 +02:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void no_misnamed_files()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2011-09-04 09:45:58 +02:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "SeriesTitle")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-04 05:05:44 +02:00
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.TheFirst(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title1.avi")
|
|
|
|
|
.TheNext(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title2.avi")
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.Series = series)
|
|
|
|
|
.TheFirst(1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[0])
|
|
|
|
|
.TheNext(1)
|
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[1])
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), episodeFiles[0]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("Title1");
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("Title2");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var totalItems = 0;
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
misnamedEpisodes.Should().HaveCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void all_misnamed_files()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2011-09-04 09:45:58 +02:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "SeriesTitle")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-04 05:05:44 +02:00
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.TheFirst(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title1.avi")
|
|
|
|
|
.TheNext(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title2.avi")
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.Series = series)
|
|
|
|
|
.TheFirst(1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[0])
|
|
|
|
|
.TheNext(1)
|
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[1])
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), episodeFiles[0]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("New Title 1");
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("New Title 2");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var totalItems = 0;
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
misnamedEpisodes.Should().HaveCount(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void one_misnamed_file()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2011-09-04 09:45:58 +02:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "SeriesTitle")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-04 05:05:44 +02:00
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.TheFirst(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title1.avi")
|
|
|
|
|
.TheNext(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title2.avi")
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.Series = series)
|
|
|
|
|
.TheFirst(1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[0])
|
|
|
|
|
.TheNext(1)
|
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[1])
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), episodeFiles[0]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("New Title 1");
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), episodeFiles[1]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("Title2");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var totalItems = 0;
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
misnamedEpisodes.Should().HaveCount(1);
|
|
|
|
|
misnamedEpisodes[0].CurrentName.Should().Be("Title1");
|
|
|
|
|
misnamedEpisodes[0].ProperName.Should().Be("New Title 1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void misnamed_multi_episode_file()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2011-09-04 09:45:58 +02:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "SeriesTitle")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-04 05:05:44 +02:00
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.TheFirst(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title1.avi")
|
|
|
|
|
.TheNext(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title2.avi")
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(3)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.Series = series)
|
|
|
|
|
.TheFirst(2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[0])
|
|
|
|
|
.TheNext(1)
|
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[1])
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0], episodes[1] }, It.IsAny<Series>(), episodeFiles[0]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("New Title 1");
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("Title2");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var totalItems = 0;
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
misnamedEpisodes.Should().HaveCount(1);
|
|
|
|
|
misnamedEpisodes[0].CurrentName.Should().Be("Title1");
|
|
|
|
|
misnamedEpisodes[0].ProperName.Should().Be("New Title 1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void no_misnamed_multi_episode_file()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2011-09-04 09:45:58 +02:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "SeriesTitle")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-04 05:05:44 +02:00
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.TheFirst(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 1)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title1.avi")
|
|
|
|
|
.TheNext(1)
|
2013-03-01 08:03:41 +01:00
|
|
|
|
.With(f => f.Id = 2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(f => f.Path = @"C:\Test\Title2.avi")
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(3)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.Series = series)
|
|
|
|
|
.TheFirst(2)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[0])
|
|
|
|
|
.TheNext(1)
|
|
|
|
|
.With(e => e.EpisodeFile = episodeFiles[1])
|
2013-03-04 00:18:43 +01:00
|
|
|
|
.Build().ToList();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0], episodes[1] }, It.IsAny<Series>(), episodeFiles[0]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("Title1");
|
|
|
|
|
|
2013-03-06 22:20:33 +01:00
|
|
|
|
Mocker.GetMock<IBuildFileNames>()
|
2013-03-06 22:35:39 +01:00
|
|
|
|
.Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1]))
|
2011-09-04 05:05:44 +02:00
|
|
|
|
.Returns("Title2");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var totalItems = 0;
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
|
2011-09-04 05:05:44 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
misnamedEpisodes.Should().HaveCount(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|