/src/NzbDrone.Core.Test/Profiles/Releases/PreferredWordService/GetMatchingPreferredWordsFixture.cs

https://github.com/NzbDrone/NzbDrone · C# · 141 lines · 118 code · 23 blank · 0 comment · 0 complexity · d20664543b99b78db71b202f6266a690 MD5 · raw file

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using FizzWare.NBuilder;
  4. using FluentAssertions;
  5. using Moq;
  6. using NUnit.Framework;
  7. using NzbDrone.Core.Profiles.Releases;
  8. using NzbDrone.Core.Test.Framework;
  9. using NzbDrone.Core.Tv;
  10. namespace NzbDrone.Core.Test.Profiles.Releases.PreferredWordService
  11. {
  12. [TestFixture]
  13. public class GetMatchingPreferredWordsFixture : CoreTest<Core.Profiles.Releases.PreferredWordService>
  14. {
  15. private Series _series = null;
  16. private List<ReleaseProfile> _releaseProfiles = null;
  17. private List<ReleaseProfile> _namedReleaseProfiles = null;
  18. private string _title = "Series.Title.S01E01.extended.720p.HDTV.x264-Sonarr";
  19. [SetUp]
  20. public void Setup()
  21. {
  22. _series = Builder<Series>.CreateNew()
  23. .With(s => s.Tags = new HashSet<int>(new[] {1, 2}))
  24. .Build();
  25. _releaseProfiles = new List<ReleaseProfile>();
  26. _releaseProfiles.Add(new ReleaseProfile
  27. {
  28. Preferred = new List<KeyValuePair<string, int>>
  29. {
  30. new KeyValuePair<string, int>("x264", 5),
  31. new KeyValuePair<string, int>("x265", -10)
  32. }
  33. });
  34. _namedReleaseProfiles = new List<ReleaseProfile>();
  35. _namedReleaseProfiles.Add(new ReleaseProfile
  36. {
  37. Name = "CodecProfile",
  38. Preferred = new List<KeyValuePair<string, int>>
  39. {
  40. new KeyValuePair<string, int>("x264", 5),
  41. new KeyValuePair<string, int>("x265", -10)
  42. }
  43. });
  44. _namedReleaseProfiles.Add(new ReleaseProfile
  45. {
  46. Name = "EditionProfile",
  47. Preferred = new List<KeyValuePair<string, int>>
  48. {
  49. new KeyValuePair<string, int>("extended", 5),
  50. new KeyValuePair<string, int>("uncut", -10)
  51. }
  52. });
  53. Mocker.GetMock<ITermMatcherService>()
  54. .Setup(s => s.MatchingTerm(It.IsAny<string>(), _title))
  55. .Returns<string, string>((term, title) => title.Contains(term) ? term : null);
  56. }
  57. private void GivenReleaseProfile()
  58. {
  59. Mocker.GetMock<IReleaseProfileService>()
  60. .Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
  61. .Returns(_releaseProfiles);
  62. }
  63. private void GivenNamedReleaseProfile()
  64. {
  65. Mocker.GetMock<IReleaseProfileService>()
  66. .Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
  67. .Returns(_namedReleaseProfiles);
  68. }
  69. [Test]
  70. public void should_return_empty_list_when_there_are_no_release_profiles()
  71. {
  72. Mocker.GetMock<IReleaseProfileService>()
  73. .Setup(s => s.EnabledForTags(It.IsAny<HashSet<int>>(), It.IsAny<int>()))
  74. .Returns(new List<ReleaseProfile>());
  75. var matchingResults = Subject.GetMatchingPreferredWords(_series, _title);
  76. matchingResults.All.Should().BeEmpty();
  77. }
  78. [Test]
  79. public void should_return_empty_list_when_there_are_no_matching_preferred_words_from_unnamedprofile()
  80. {
  81. _releaseProfiles.First().Preferred.RemoveAt(0);
  82. GivenReleaseProfile();
  83. var matchingResults = Subject.GetMatchingPreferredWords(_series, _title);
  84. matchingResults.All.Should().BeEmpty();
  85. }
  86. [Test]
  87. public void should_return_list_of_matching_terms_from_unnamedprofile()
  88. {
  89. GivenReleaseProfile();
  90. var matchingResults = Subject.GetMatchingPreferredWords(_series, _title);
  91. matchingResults.All.Should().Equal(new[] { "x264" });
  92. }
  93. [Test]
  94. public void should_return_empty_list_when_there_are_no_matching_preferred_words_from_namedprofiles()
  95. {
  96. _namedReleaseProfiles.First().Preferred.RemoveAt(0);
  97. _namedReleaseProfiles.Skip(1).First().Preferred.RemoveAt(0);
  98. GivenNamedReleaseProfile();
  99. var matchingResults = Subject.GetMatchingPreferredWords(_series, _title);
  100. matchingResults.All.Should().BeEmpty();
  101. }
  102. [Test]
  103. public void should_return_list_of_matching_terms_from_multiple_namedprofiles()
  104. {
  105. GivenNamedReleaseProfile();
  106. var matchingResults = Subject.GetMatchingPreferredWords(_series, _title);
  107. matchingResults.ByReleaseProfile.Should().ContainKey("CodecProfile").WhichValue.Should().Equal(new[] { "x264" });
  108. matchingResults.ByReleaseProfile.Should().ContainKey("EditionProfile").WhichValue.Should().Equal(new[] { "extended" });
  109. }
  110. [Test]
  111. public void should_return_list_of_matching_terms_from_multiple_namedprofiles_all()
  112. {
  113. GivenNamedReleaseProfile();
  114. var matchingResults = Subject.GetMatchingPreferredWords(_series, _title);
  115. matchingResults.All.Should().Equal(new[] { "x264", "extended" });
  116. }
  117. }
  118. }