From 6e523ce7a8b1070bbbc87ce19a79988b948d8471 Mon Sep 17 00:00:00 2001 From: Sean McArdle Date: Tue, 23 Apr 2024 16:07:37 -0700 Subject: [PATCH] Added test for case insensitive comparison. --- McRule.Tests/IDictionarySelector.cs | 22 ++++++++++++++++++++++ McRule.Tests/TestPolicies.cs | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/McRule.Tests/IDictionarySelector.cs b/McRule.Tests/IDictionarySelector.cs index 6ec960a..f54ed4c 100644 --- a/McRule.Tests/IDictionarySelector.cs +++ b/McRule.Tests/IDictionarySelector.cs @@ -53,6 +53,15 @@ namespace McRule.Tests { { "Surname", "McArdle" }, { "Team", "Children" }, } + }, + new SomeContext() { + Name = "Nerd Son", + Context = new ContextStringDictionary() { + { "GivenName", "Thing-2"}, + { "Surname", "McArdle" }, + { "Team", "Children" }, + { "Department", "it" }, + } } }; @@ -75,6 +84,19 @@ namespace McRule.Tests { Assert.AreEqual(filteredContexts.Count(), 2); } + [Test] + public void CanSelectDictionaryValuesByKeyCaseInsensitive() { + var lambda = itPeopleCaseless.GetPredicateExpression(); + + var filter = lambda.Compile(); + var localContext = SomeContexts; + var filteredContexts = localContext.Select(x => x.Context) + .Where(x => x.ContainsKey("Department")) // Skip entry with a missing key + .Where(filter); + + Assert.NotNull(filteredContexts); + Assert.AreEqual(filteredContexts.Count(), 3); + } [Test] public void CanSelectDictionaryValueWithContainsKeyCheck() { diff --git a/McRule.Tests/TestPolicies.cs b/McRule.Tests/TestPolicies.cs index 74ca50a..45d1ca2 100644 --- a/McRule.Tests/TestPolicies.cs +++ b/McRule.Tests/TestPolicies.cs @@ -117,6 +117,16 @@ namespace McRule.Tests { RuleOperator = RuleOperator.And }; + public static ExpressionPolicy itPeopleCaseless = new ExpressionPolicy { + Rules = new List + { + ("ContextDictionary", "Department", "~IT").ToFilterRule(), + ("ContextStringDictionary", "Department", "~IT").ToFilterRule(), + ("SomeContext", "Context.Department", "~IT").ToFilterRule(), // Same rule but with nested selector + }, + RuleOperator = RuleOperator.And + }; + #endregion } }