Added test for case insensitive comparison.

main
Sean McArde 2024-04-23 16:07:37 -07:00
parent 0481f352d5
commit 6e523ce7a8
2 changed files with 32 additions and 0 deletions

View File

@ -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<ContextStringDictionary>();
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() {

View File

@ -117,6 +117,16 @@ namespace McRule.Tests {
RuleOperator = RuleOperator.And
};
public static ExpressionPolicy itPeopleCaseless = new ExpressionPolicy {
Rules = new List<ExpressionRule>
{
("ContextDictionary", "Department", "~IT").ToFilterRule(),
("ContextStringDictionary", "Department", "~IT").ToFilterRule(),
("SomeContext", "Context.Department", "~IT").ToFilterRule(), // Same rule but with nested selector
},
RuleOperator = RuleOperator.And
};
#endregion
}
}