public void CreateComparerOnTheFlyUsingReflection() { var containsRule = new ContainsValueRule <string> { EqualityComparerClassName = "System.StringComparer", EqualityComparerPropertyName = "OrdinalIgnoreCase", CollectionToSearch = { "one", "two", "three", "four", "five", "six" } }; var compileResult = containsRule.Compile(); compileResult.Should().BeTrue(); _testOutputHelper.WriteLine($"{nameof(containsRule)}:{Environment.NewLine}" + $"{containsRule.ExpressionDebugView()}"); var a1 = containsRule.ContainsValue("One"); a1.Should().BeTrue(); var a2 = containsRule.ContainsValue("tWo"); a2.Should().BeTrue(); var a7 = containsRule.ContainsValue("seven"); a7.Should().BeFalse(); }
public void ContainsValueTestForIntCollection(int valueToSearch, bool expectedResult) { var containsRule = new ContainsValueRule <int> { EqualityComparer = null, CollectionToSearch = { 1, 2, 3, 4, 5, 6 } }; var compileResult = containsRule.Compile(); compileResult.Should().BeTrue(); _testOutputHelper.WriteLine($"{nameof(containsRule)}:{Environment.NewLine}" + $"{containsRule.ExpressionDebugView()}"); var containsValue = containsRule.ContainsValue(valueToSearch); _testOutputHelper.WriteLine($"expected: {expectedResult} - actual: {containsValue}"); containsValue.Should().Be(expectedResult); }
public void ContainsValueTestCaseSensitive(string valueToSearch, bool expectedResult) { var containsRule = new ContainsValueRule <string> { EqualityComparer = StringComparer.Ordinal, CollectionToSearch = { "one", "two", "three", "four", "five", "six" } }; var compileResult = containsRule.Compile(); compileResult.Should().BeTrue(); _testOutputHelper.WriteLine($"{nameof(containsRule)}:{Environment.NewLine}" + $"{containsRule.ExpressionDebugView()}"); var containsValue = containsRule.ContainsValue(valueToSearch); _testOutputHelper.WriteLine($"expected: {expectedResult} - actual: {containsValue}"); containsValue.Should().Be(expectedResult); }