diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index ea4bab30e..dbb7a8e11 100644
--- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -351,6 +351,7 @@
+
diff --git a/src/NzbDrone.Core.Test/Profiles/Releases/PreferredWordService/GetMatchingPreferredWordsFixture.cs b/src/NzbDrone.Core.Test/Profiles/Releases/PreferredWordService/GetMatchingPreferredWordsFixture.cs
new file mode 100644
index 000000000..bb91630ae
--- /dev/null
+++ b/src/NzbDrone.Core.Test/Profiles/Releases/PreferredWordService/GetMatchingPreferredWordsFixture.cs
@@ -0,0 +1,79 @@
+using System.Collections.Generic;
+using System.Linq;
+using FizzWare.NBuilder;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Core.Profiles.Releases;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Core.Tv;
+
+namespace NzbDrone.Core.Test.Profiles.Releases.PreferredWordService
+{
+ [TestFixture]
+ public class GetMatchingPreferredWordsFixture : CoreTest
+ {
+ private Series _series = null;
+ private List _releaseProfiles = null;
+ private string _title = "Series.Title.S01E01.720p.HDTV.x264-Sonarr";
+
+ [SetUp]
+ public void Setup()
+ {
+ _series = Builder.CreateNew()
+ .With(s => s.Tags = new HashSet(new[] {1, 2}))
+ .Build();
+
+ _releaseProfiles = new List();
+
+ _releaseProfiles.Add(new ReleaseProfile
+ {
+ Preferred = new List>
+ {
+ new KeyValuePair("x264", 5),
+ new KeyValuePair("x265", -10)
+ }
+ });
+
+
+ Mocker.GetMock()
+ .Setup(s => s.MatchingTerm(It.IsAny(), _title))
+ .Returns((term, title) => title.Contains(term) ? term : null);
+ }
+
+
+ private void GivenReleaseProfile()
+ {
+ Mocker.GetMock()
+ .Setup(s => s.AllForTags(It.IsAny>()))
+ .Returns(_releaseProfiles);
+ }
+
+ [Test]
+ public void should_return_empty_list_when_there_are_no_release_profiles()
+ {
+ Mocker.GetMock()
+ .Setup(s => s.AllForTags(It.IsAny>()))
+ .Returns(new List());
+
+ Subject.GetMatchingPreferredWords(_series, _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(_series, _title).Should().BeEmpty();
+ }
+
+ [Test]
+ public void should_return_list_of_matching_terms()
+ {
+ GivenReleaseProfile();
+
+ Subject.GetMatchingPreferredWords(_series, _title).Should().Contain(new[] {"x264"});
+ }
+ }
+}
diff --git a/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs b/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs
index 170521f85..305123420 100644
--- a/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs
+++ b/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs
@@ -16,7 +16,12 @@
public string MatchingTerm(string value)
{
- return _term;
+ if (value.ToLowerInvariant().Contains(_term))
+ {
+ return _term;
+ }
+
+ return null;
}
}
}