mirror of https://github.com/sean-m/McRule.git
Added test for case insensitive comparison.
parent
0481f352d5
commit
6e523ce7a8
|
@ -53,6 +53,15 @@ namespace McRule.Tests {
|
||||||
{ "Surname", "McArdle" },
|
{ "Surname", "McArdle" },
|
||||||
{ "Team", "Children" },
|
{ "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);
|
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]
|
[Test]
|
||||||
public void CanSelectDictionaryValueWithContainsKeyCheck() {
|
public void CanSelectDictionaryValueWithContainsKeyCheck() {
|
||||||
|
|
|
@ -117,6 +117,16 @@ namespace McRule.Tests {
|
||||||
RuleOperator = RuleOperator.And
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue