1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-30 19:56:54 +00:00
Sonarr/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs

261 lines
9.1 KiB
C#
Raw Normal View History

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