1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs

268 lines
10 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
2011-12-15 07:15:53 +03:00
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
2011-12-15 07:15:53 +03:00
public class MisnamedProviderTest : CoreTest
{
[Test]
public void no_misnamed_files()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(f => f.EpisodeFileId = 1)
.With(f => f.Path = @"C:\Test\Title1.avi")
.TheNext(1)
.With(f => f.EpisodeFileId = 2)
.With(f => f.Path = @"C:\Test\Title2.avi")
.Build();
var episodes = Builder<Episode>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.All()
.With(e => e.Series = series)
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = episodeFiles[0])
.TheNext(1)
.With(e => e.EpisodeFileId = 2)
.With(e => e.EpisodeFile = episodeFiles[1])
.Build();
2011-12-15 07:15:53 +03:00
WithStrictMocker();
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[0]))
.Returns("Title1");
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[1]))
.Returns("Title2");
//Act
var totalItems = 0;
2011-12-15 07:15:53 +03:00
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert
misnamedEpisodes.Should().HaveCount(0);
}
[Test]
public void all_misnamed_files()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(f => f.EpisodeFileId = 1)
.With(f => f.Path = @"C:\Test\Title1.avi")
.TheNext(1)
.With(f => f.EpisodeFileId = 2)
.With(f => f.Path = @"C:\Test\Title2.avi")
.Build();
var episodes = Builder<Episode>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.All()
.With(e => e.Series = series)
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = episodeFiles[0])
.TheNext(1)
.With(e => e.EpisodeFileId = 2)
.With(e => e.EpisodeFile = episodeFiles[1])
.Build();
2011-12-15 07:15:53 +03:00
WithStrictMocker();
2011-12-15 07:15:53 +03:00
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[0]))
.Returns("New Title 1");
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[1]))
.Returns("New Title 2");
//Act
var totalItems = 0;
2011-12-15 07:15:53 +03:00
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert
misnamedEpisodes.Should().HaveCount(2);
}
[Test]
public void one_misnamed_file()
{
//Setup
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(f => f.EpisodeFileId = 1)
.With(f => f.Path = @"C:\Test\Title1.avi")
.TheNext(1)
.With(f => f.EpisodeFileId = 2)
.With(f => f.Path = @"C:\Test\Title2.avi")
.Build();
var episodes = Builder<Episode>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.All()
.With(e => e.Series = series)
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = episodeFiles[0])
.TheNext(1)
.With(e => e.EpisodeFileId = 2)
.With(e => e.EpisodeFile = episodeFiles[1])
.Build();
2011-12-15 07:15:53 +03:00
WithStrictMocker();
2011-12-15 07:15:53 +03:00
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[0]))
.Returns("New Title 1");
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[1]))
.Returns("Title2");
//Act
var totalItems = 0;
2011-12-15 07:15:53 +03:00
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//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
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(f => f.EpisodeFileId = 1)
.With(f => f.Path = @"C:\Test\Title1.avi")
.TheNext(1)
.With(f => f.EpisodeFileId = 2)
.With(f => f.Path = @"C:\Test\Title2.avi")
.Build();
var episodes = Builder<Episode>.CreateListOfSize(3)
2011-10-19 00:46:06 +03:00
.All()
.With(e => e.Series = series)
.TheFirst(2)
2011-10-23 08:39:14 +03:00
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = episodeFiles[0])
.TheNext(1)
.With(e => e.EpisodeFileId = 2)
.With(e => e.EpisodeFile = episodeFiles[1])
.Build();
2011-12-15 07:15:53 +03:00
WithStrictMocker();
2011-12-15 07:15:53 +03:00
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[0]))
.Returns("New Title 1");
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[1]))
.Returns("Title2");
//Act
var totalItems = 0;
2011-12-15 07:15:53 +03:00
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//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
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-19 00:46:06 +03:00
.TheFirst(1)
2011-10-23 08:39:14 +03:00
.With(f => f.EpisodeFileId = 1)
.With(f => f.Path = @"C:\Test\Title1.avi")
.TheNext(1)
.With(f => f.EpisodeFileId = 2)
.With(f => f.Path = @"C:\Test\Title2.avi")
.Build();
var episodes = Builder<Episode>.CreateListOfSize(3)
2011-10-19 00:46:06 +03:00
.All()
.With(e => e.Series = series)
.TheFirst(2)
2011-10-23 08:39:14 +03:00
.With(e => e.EpisodeFileId = 1)
.With(e => e.EpisodeFile = episodeFiles[0])
.TheNext(1)
.With(e => e.EpisodeFileId = 2)
.With(e => e.EpisodeFile = episodeFiles[1])
.Build();
2011-12-15 07:15:53 +03:00
WithStrictMocker();
2011-12-15 07:15:53 +03:00
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[0], episodes[1] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[0]))
.Returns("Title1");
2011-12-15 07:15:53 +03:00
Mocker.GetMock<MediaFileProvider>()
.Setup(c => c.GetNewFilename(new List<Episode> { episodes[2] }, "SeriesTitle", It.IsAny<QualityTypes>(), It.IsAny<bool>(), episodeFiles[1]))
.Returns("Title2");
//Act
var totalItems = 0;
2011-12-15 07:15:53 +03:00
var misnamedEpisodes = Mocker.Resolve<MisnamedProvider>().MisnamedFiles(1, 10, out totalItems);
//Assert
misnamedEpisodes.Should().HaveCount(0);
}
}
}