diff --git a/CHANGELOG.md b/CHANGELOG.md index 35e514ec..4ba60af1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Sonarr: Fix unexpected missing terms when using filters. (#69) + ## [2.0.1] - 2022-05-19 ### Fixed diff --git a/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileDataFiltererTest.cs b/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileDataFiltererTest.cs index bcf78256..31c710c5 100644 --- a/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileDataFiltererTest.cs +++ b/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileDataFiltererTest.cs @@ -18,7 +18,9 @@ public class ReleaseProfileDataFiltererTest { new() {TrashId = "1", Term = "term1"}, new() {TrashId = "2", Term = "term2"}, - new() {TrashId = "3", Term = "term3"} + new() {TrashId = "3", Term = "term3"}, + new() {Term = "term4"}, + new() {Term = "term5"} }; var result = sut.IncludeTerms(terms, filter); @@ -42,7 +44,9 @@ public class ReleaseProfileDataFiltererTest { new() {TrashId = "1", Term = "term1"}, new() {TrashId = "2", Term = "term2"}, - new() {TrashId = "3", Term = "term3"} + new() {TrashId = "3", Term = "term3"}, + new() {Term = "term4"}, + new() {Term = "term5"} } }, new() @@ -77,14 +81,18 @@ public class ReleaseProfileDataFiltererTest { new() {TrashId = "1", Term = "term1"}, new() {TrashId = "2", Term = "term2"}, - new() {TrashId = "3", Term = "term3"} + new() {TrashId = "3", Term = "term3"}, + new() {Term = "term4"}, + new() {Term = "term5"} }; var result = sut.ExcludeTerms(terms, filter); result.Should().BeEquivalentTo(new TermData[] { - new() {TrashId = "3", Term = "term3"} + new() {TrashId = "3", Term = "term3"}, + new() {Term = "term4"}, + new() {Term = "term5"} }); } @@ -101,7 +109,9 @@ public class ReleaseProfileDataFiltererTest { new() {TrashId = "1", Term = "term1"}, new() {TrashId = "2", Term = "term2"}, - new() {TrashId = "3", Term = "term3"} + new() {TrashId = "3", Term = "term3"}, + new() {Term = "term4"}, + new() {Term = "term5"} } }, new() @@ -109,7 +119,9 @@ public class ReleaseProfileDataFiltererTest Score = 20, Terms = new TermData[] { - new() {TrashId = "4", Term = "term4"} + new() {TrashId = "4", Term = "term4"}, + new() {Term = "term6"}, + new() {Term = "term7"} } } }; @@ -123,7 +135,9 @@ public class ReleaseProfileDataFiltererTest Score = 10, Terms = new TermData[] { - new() {TrashId = "3", Term = "term3"} + new() {TrashId = "3", Term = "term3"}, + new() {Term = "term4"}, + new() {Term = "term5"} } }, new() @@ -131,7 +145,9 @@ public class ReleaseProfileDataFiltererTest Score = 20, Terms = new TermData[] { - new() {TrashId = "4", Term = "term4"} + new() {TrashId = "4", Term = "term4"}, + new() {Term = "term6"}, + new() {Term = "term7"} } } }); diff --git a/src/TrashLib/Sonarr/ReleaseProfile/ReleaseProfileDataFilterer.cs b/src/TrashLib/Sonarr/ReleaseProfile/ReleaseProfileDataFilterer.cs index dc21eecb..e77be0e0 100644 --- a/src/TrashLib/Sonarr/ReleaseProfile/ReleaseProfileDataFilterer.cs +++ b/src/TrashLib/Sonarr/ReleaseProfile/ReleaseProfileDataFilterer.cs @@ -21,22 +21,22 @@ public class ReleaseProfileDataFilterer } public ReadOnlyCollection ExcludeTerms(IEnumerable terms, - IEnumerable includeFilter) + IEnumerable excludeFilter) { return terms - .ExceptBy(includeFilter, x => x.TrashId, StringComparer.InvariantCultureIgnoreCase) + .Where(x => !excludeFilter.Contains(x.TrashId, StringComparer.InvariantCultureIgnoreCase)) .IsValid(new TermDataValidator(), (e, x) => LogInvalidTerm(e, $"Exclude: {x}")) .ToList().AsReadOnly(); } public ReadOnlyCollection ExcludeTerms(IEnumerable terms, - IReadOnlyCollection includeFilter) + IReadOnlyCollection excludeFilter) { return terms .Select(x => new PreferredTermData { Score = x.Score, - Terms = ExcludeTerms(x.Terms, includeFilter) + Terms = ExcludeTerms(x.Terms, excludeFilter) }) .IsValid(new PreferredTermDataValidator(), (e, x) => LogInvalidTerm(e, $"Exclude Preferred: {x}")) .ToList() @@ -47,9 +47,8 @@ public class ReleaseProfileDataFilterer IEnumerable includeFilter) { return terms - .IntersectBy(includeFilter, x => x.TrashId, StringComparer.InvariantCultureIgnoreCase) - .IsValid(new TermDataValidator(), - (e, x) => LogInvalidTerm(e, $"Include: {x}")) + .Where(x => includeFilter.Contains(x.TrashId, StringComparer.InvariantCultureIgnoreCase)) + .IsValid(new TermDataValidator(), (e, x) => LogInvalidTerm(e, $"Include: {x}")) .ToList().AsReadOnly(); }