New: Custom Formats

Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
Qstick
2022-01-23 23:42:41 -06:00
parent 4a3062deae
commit dbb6ef7664
185 changed files with 6974 additions and 810 deletions
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Books;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.ImportLists;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Profiles.Qualities;
@@ -13,11 +15,15 @@ namespace NzbDrone.Core.Test.Profiles
{
[TestFixture]
public class ProfileServiceFixture : CoreTest<QualityProfileService>
public class QualityProfileServiceFixture : CoreTest<QualityProfileService>
{
[Test]
public void init_should_add_default_profiles()
{
Mocker.GetMock<ICustomFormatService>()
.Setup(s => s.All())
.Returns(new List<CustomFormat>());
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IProfileRepository>()
@@ -1,94 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Books;
using NzbDrone.Core.Profiles.Releases;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Profiles.Releases.PreferredWordService
{
[TestFixture]
public class CalculateFixture : CoreTest<Core.Profiles.Releases.PreferredWordService>
{
private Author _author = null;
private List<ReleaseProfile> _releaseProfiles = null;
private string _title = "Author.Name-Book.Title.2018.FLAC.24bit-Readarr";
[SetUp]
public void Setup()
{
_author = Builder<Author>.CreateNew()
.With(s => s.Tags = new HashSet<int>(new[] { 1, 2 }))
.Build();
_releaseProfiles = new List<ReleaseProfile>();
_releaseProfiles.Add(new ReleaseProfile
{
Preferred = new List<KeyValuePair<string, int>>
{
new KeyValuePair<string, int>("24bit", 5),
new KeyValuePair<string, int>("16bit", -10)
}
});
Mocker.GetMock<IReleaseProfileService>()
.Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
.Returns(_releaseProfiles);
}
private void GivenMatchingTerms(params string[] terms)
{
Mocker.GetMock<ITermMatcherService>()
.Setup(s => s.IsMatch(It.IsAny<string>(), _title))
.Returns<string, string>((term, title) => terms.Contains(term));
}
[Test]
public void should_return_0_when_there_are_no_release_profiles()
{
Mocker.GetMock<IReleaseProfileService>()
.Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
.Returns(new List<ReleaseProfile>());
Subject.Calculate(_author, _title, 0).Should().Be(0);
}
[Test]
public void should_return_0_when_there_are_no_matching_preferred_words()
{
GivenMatchingTerms();
Subject.Calculate(_author, _title, 0).Should().Be(0);
}
[Test]
public void should_calculate_positive_score()
{
GivenMatchingTerms("24bit");
Subject.Calculate(_author, _title, 0).Should().Be(5);
}
[Test]
public void should_calculate_negative_score()
{
GivenMatchingTerms("16bit");
Subject.Calculate(_author, _title, 0).Should().Be(-10);
}
[Test]
public void should_calculate_using_multiple_profiles()
{
_releaseProfiles.Add(_releaseProfiles.First());
GivenMatchingTerms("24bit");
Subject.Calculate(_author, _title, 0).Should().Be(10);
}
}
}
@@ -1,77 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Books;
using NzbDrone.Core.Profiles.Releases;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Profiles.Releases.PreferredWordService
{
[TestFixture]
public class GetMatchingPreferredWordsFixture : CoreTest<Core.Profiles.Releases.PreferredWordService>
{
private Author _author = null;
private List<ReleaseProfile> _releaseProfiles = null;
private string _title = "Author.Name-Book.Name-2018-Flac-Vinyl-Readarr";
[SetUp]
public void Setup()
{
_author = Builder<Author>.CreateNew()
.With(s => s.Tags = new HashSet<int>(new[] { 1, 2 }))
.Build();
_releaseProfiles = new List<ReleaseProfile>();
_releaseProfiles.Add(new ReleaseProfile
{
Preferred = new List<KeyValuePair<string, int>>
{
new KeyValuePair<string, int>("Vinyl", 5),
new KeyValuePair<string, int>("CD", -10)
}
});
Mocker.GetMock<ITermMatcherService>()
.Setup(s => s.MatchingTerm(It.IsAny<string>(), _title))
.Returns<string, string>((term, title) => title.Contains(term) ? term : null);
}
private void GivenReleaseProfile()
{
Mocker.GetMock<IReleaseProfileService>()
.Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
.Returns(_releaseProfiles);
}
[Test]
public void should_return_empty_list_when_there_are_no_release_profiles()
{
Mocker.GetMock<IReleaseProfileService>()
.Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
.Returns(new List<ReleaseProfile>());
Subject.GetMatchingPreferredWords(_author, _title).Should().BeEmpty();
}
[Test]
public void should_return_empty_list_when_there_are_no_matching_preferred_words()
{
_releaseProfiles.First().Preferred.RemoveAt(0);
GivenReleaseProfile();
Subject.GetMatchingPreferredWords(_author, _title).Should().BeEmpty();
}
[Test]
public void should_return_list_of_matching_terms()
{
GivenReleaseProfile();
Subject.GetMatchingPreferredWords(_author, _title).Should().Contain(new[] { "Vinyl" });
}
}
}