mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-27 23:06:29 -04:00
New: Custom Formats
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
+2
-2
@@ -6,12 +6,12 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
@@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeFileMovingServiceTests
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.BuildFilePath(It.IsAny<List<Episode>>(), It.IsAny<Series>(), It.IsAny<EpisodeFile>(), It.IsAny<string>(), It.IsAny<NamingConfig>(), It.IsAny<PreferredWordMatchResults>()))
|
||||
.Setup(s => s.BuildFilePath(It.IsAny<List<Episode>>(), It.IsAny<Series>(), It.IsAny<EpisodeFile>(), It.IsAny<string>(), It.IsAny<NamingConfig>(), It.IsAny<List<CustomFormat>>()))
|
||||
.Returns(@"C:\Test\TV\Series\Season 01\File Name.avi".AsOsAgnostic());
|
||||
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
[TestFixture]
|
||||
public class EpisodeFilePreferredWordCalculatorFixture : CoreTest<EpisodeFilePreferredWordCalculator>
|
||||
{
|
||||
private readonly KeyValuePair<string, int> _positiveScore = new KeyValuePair<string, int>("Positive", 10);
|
||||
private readonly KeyValuePair<string, int> _negativeScore = new KeyValuePair<string, int>("Negative", -10);
|
||||
private KeyValuePair<string, int> _neutralScore = new KeyValuePair<string, int>("Neutral", 0);
|
||||
private Series _series;
|
||||
private EpisodeFile _episodeFile;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew().Build();
|
||||
_episodeFile = Builder<EpisodeFile>.CreateNew().Build();
|
||||
|
||||
Mocker.GetMock<IPreferredWordService>()
|
||||
.Setup(s => s.GetMatchingPreferredWordsAndScores(It.IsAny<Series>(), It.IsAny<string>(), 0))
|
||||
.Returns(new List<KeyValuePair<string, int>>());
|
||||
}
|
||||
|
||||
private void GivenPreferredWordScore(string title, params KeyValuePair<string, int>[] matches)
|
||||
{
|
||||
Mocker.GetMock<IPreferredWordService>()
|
||||
.Setup(s => s.GetMatchingPreferredWordsAndScores(It.IsAny<Series>(), title, 0))
|
||||
.Returns(matches.ToList());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_relative_file_name_when_it_is_higher_than_scene_name()
|
||||
{
|
||||
GivenPreferredWordScore(_episodeFile.SceneName, _positiveScore);
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_full_file_name_when_relative_file_name_is_not_available()
|
||||
{
|
||||
_episodeFile.SceneName = null;
|
||||
_episodeFile.RelativePath = null;
|
||||
|
||||
GivenPreferredWordScore(_episodeFile.Path, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_relative_file_name_when_scene_name_is_null()
|
||||
{
|
||||
_episodeFile.SceneName = null;
|
||||
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_scene_name_when_higher_than_relative_file_name()
|
||||
{
|
||||
GivenPreferredWordScore(_episodeFile.SceneName, _positiveScore, _positiveScore, _positiveScore);
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(30);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_relative_file_if_available()
|
||||
{
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _positiveScore, _positiveScore);
|
||||
GivenPreferredWordScore(_episodeFile.Path, _positiveScore, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_original_path_folder_name_if_highest()
|
||||
{
|
||||
var folderName = "folder-name";
|
||||
var fileName = "file-name";
|
||||
|
||||
_episodeFile.OriginalFilePath = Path.Combine(folderName, fileName);
|
||||
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _positiveScore);
|
||||
GivenPreferredWordScore(_episodeFile.Path, _positiveScore, _positiveScore);
|
||||
GivenPreferredWordScore(folderName, _positiveScore, _positiveScore, _positiveScore);
|
||||
GivenPreferredWordScore(fileName, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(30);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_score_for_original_path_file_name_if_highest()
|
||||
{
|
||||
var folderName = "folder-name";
|
||||
var fileName = "file-name";
|
||||
|
||||
_episodeFile.OriginalFilePath = Path.Combine(folderName, fileName);
|
||||
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _positiveScore);
|
||||
GivenPreferredWordScore(_episodeFile.Path, _positiveScore, _positiveScore);
|
||||
GivenPreferredWordScore(folderName, _positiveScore, _positiveScore);
|
||||
GivenPreferredWordScore(fileName, _positiveScore, _positiveScore, _positiveScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(30);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_negative_score_if_0_result_has_no_matches()
|
||||
{
|
||||
var folderName = "folder-name";
|
||||
var fileName = "file-name";
|
||||
|
||||
_episodeFile.OriginalFilePath = Path.Combine(folderName, fileName);
|
||||
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _negativeScore);
|
||||
GivenPreferredWordScore(fileName);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(-10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_0_score_if_0_result_has_matches()
|
||||
{
|
||||
var folderName = "folder-name";
|
||||
var fileName = "file-name";
|
||||
|
||||
_episodeFile.OriginalFilePath = Path.Combine(folderName, fileName);
|
||||
|
||||
GivenPreferredWordScore(_episodeFile.RelativePath, _negativeScore);
|
||||
GivenPreferredWordScore(_episodeFile.Path, _negativeScore);
|
||||
GivenPreferredWordScore(folderName, _negativeScore);
|
||||
GivenPreferredWordScore(fileName, _neutralScore);
|
||||
|
||||
Subject.Calculate(_series, _episodeFile).Should().Be(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
-20
@@ -1,18 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.CustomFormats;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
@@ -283,15 +287,24 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
[Test]
|
||||
public void should_return_false_if_it_is_a_preferred_word_downgrade_and_equal_language_and_quality()
|
||||
{
|
||||
var lowFormat = new List<CustomFormat> { new CustomFormat("Bad Format", new ResolutionSpecification { Value = (int)Resolution.R1080p }) { Id = 2 } };
|
||||
|
||||
CustomFormatsFixture.GivenCustomFormats(lowFormat.First());
|
||||
|
||||
_series.QualityProfile.Value.FormatItems = CustomFormatsFixture.GetSampleFormatItems();
|
||||
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(10);
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<EpisodeFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<ParsedEpisodeInfo>()))
|
||||
.Returns(lowFormat);
|
||||
|
||||
_localEpisode.PreferredWordScore = 5;
|
||||
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
@@ -318,11 +331,14 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(10);
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<EpisodeFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<ParsedEpisodeInfo>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
_localEpisode.PreferredWordScore = 5;
|
||||
_localEpisode.Quality = new QualityModel(Quality.Bluray2160p);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
@@ -349,11 +365,14 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(10);
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<EpisodeFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<ParsedEpisodeInfo>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
_localEpisode.PreferredWordScore = 5;
|
||||
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
@@ -424,11 +443,14 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(1);
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<EpisodeFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<ParsedEpisodeInfo>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
_localEpisode.PreferredWordScore = 5;
|
||||
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
@@ -454,11 +476,14 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||
.Returns(5);
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<EpisodeFile>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
Mocker.GetMock<ICustomFormatCalculationService>()
|
||||
.Setup(s => s.ParseCustomFormat(It.IsAny<ParsedEpisodeInfo>()))
|
||||
.Returns(new List<CustomFormat>());
|
||||
|
||||
_localEpisode.PreferredWordScore = 5;
|
||||
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
|
||||
Reference in New Issue
Block a user