public void IfValueContainsReturnDiffValue2(string searchValue, string expectedValue)
        {
            var valueReplacementIfBad = new ConditionalFuncRule <string, string>
            {
                ConditionRule = new ContainsValueRule <string>
                {
                    EqualityComparer   = StringComparer.OrdinalIgnoreCase,
                    CollectionToSearch = { "one", "two", "three", "four", "five", "six" }
                },
                TrueRule = new ConstantRule <string, string> {
                    Value = "six-six-six"
                },
                FalseRule = new SelfReturnRule <string>()
            };

            var compileResult = valueReplacementIfBad.Compile();

            compileResult.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(valueReplacementIfBad)}:{Environment.NewLine}" +
                                        $"{valueReplacementIfBad.ExpressionDebugView()}");

            var ruleResult = valueReplacementIfBad.Execute(searchValue);

            _testOutputHelper.WriteLine($"expected: {expectedValue} - actual: {ruleResult}");
            ruleResult.Should().Be(expectedValue);
        }
        public void ConditionalWithConstantRule3(string valueToCheck, string trueRuleValue, string falseRuleValue, bool?expectedOutput)
        {
            var containsTextRule = new ConditionalFuncRule <string, bool?>
            {
                ConditionRule = new ContainsValueRule <string>
                {
                    EqualityComparer   = StringComparer.OrdinalIgnoreCase,
                    CollectionToSearch = { "one", "two", "three", "four", "five", "six" }
                },
                TrueRule = new ConstantRule <string, bool?> {
                    Value = trueRuleValue
                },
                FalseRule = new ConstantRule <string, bool?> {
                    Value = falseRuleValue
                }
            };

            var compileResult = containsTextRule.Compile();

            compileResult.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(containsTextRule)}:{Environment.NewLine}" +
                                        $"{containsTextRule.ExpressionDebugView()}");

            var ruleResult = containsTextRule.Execute(valueToCheck);

            _testOutputHelper.WriteLine($"expected: {expectedOutput} - actual: {ruleResult}");
            ruleResult.Should().Be(expectedOutput);
        }
        public void ConditionalWithConstantRuleToAndFromJson(string valueToCheck, string expectedOutput)
        {
            var rule = new ConditionalFuncRule <string, string>
            {
                ConditionRule = new ContainsValueRule <string>
                {
                    EqualityComparerClassName    = "System.StringComparer",
                    EqualityComparerPropertyName = "OrdinalIgnoreCase",
                    CollectionToSearch           = { "one", "two", "three", "four", "five", "six" }
                },
                TrueRule = new ConstantRule <string, string> {
                    Value = "element is present in the collection"
                },
                FalseRule = new ConstantRule <string, string> {
                    Value = "element is not present in the collection"
                }
            };

            var compileResult = rule.Compile();

            compileResult.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(rule)}:{Environment.NewLine}" +
                                        $"{rule.ExpressionDebugView()}");

            var ruleResult = rule.Execute(valueToCheck);

            _testOutputHelper.WriteLine($"expected: {expectedOutput} - actual: {ruleResult}");
            ruleResult.Should().BeEquivalentTo(expectedOutput);

            // convert to json
            var ruleJson = JsonConvert.SerializeObject(rule, new JsonConverterForRule());

            _testOutputHelper.WriteLine($"{nameof(ruleJson)}:{Environment.NewLine}{ruleJson}");
            // re-hydrate from json
            var ruleFromJson = JsonConvert.DeserializeObject <Rule>(ruleJson, new JsonConverterForRule());

            compileResult = ruleFromJson.Compile();
            compileResult.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(ruleFromJson)}:{Environment.NewLine}" +
                                        $"{ruleFromJson.ExpressionDebugView()}");

            ruleResult = ((ConditionalFuncRule <string, string>)ruleFromJson).Execute(valueToCheck);
            _testOutputHelper.WriteLine($"expected: {expectedOutput} - actual: {ruleResult}");
            ruleResult.Should().BeEquivalentTo(expectedOutput);
        }
        public void IfValueContainsReturnDiffValue2ToAndFromJson(string searchValue, string expectedValue)
        {
            var valueReplacementIfBad = new ConditionalFuncRule <string, string>
            {
                ConditionRule = new ContainsValueRule <string>
                {
                    EqualityComparerClassName    = "System.StringComparer",
                    EqualityComparerPropertyName = "OrdinalIgnoreCase",
                    CollectionToSearch           = { "one", "two", "three", "four", "five", "six" }
                },
                TrueRule = new ConstantRule <string, string> {
                    Value = "six-six-six"
                },
                FalseRule = new SelfReturnRule <string>()
            };

            var compileResult = valueReplacementIfBad.Compile();

            compileResult.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(valueReplacementIfBad)}:{Environment.NewLine}" +
                                        $"{valueReplacementIfBad.ExpressionDebugView()}");

            var ruleResult = valueReplacementIfBad.Execute(searchValue);

            _testOutputHelper.WriteLine($"expected: {expectedValue} - actual: {ruleResult}");
            ruleResult.Should().Be(expectedValue);

            var converter = new JsonConverterForRule();
            // convert to json
            var ruleJson = JsonConvert.SerializeObject(valueReplacementIfBad, converter);

            _testOutputHelper.WriteLine(ruleJson);
            // re-hydrate
            var ruleFromJson = JsonConvert.DeserializeObject <ConditionalFuncRule <string, string> >(ruleJson, converter);

            var compileResult2 = ruleFromJson.Compile();

            compileResult2.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(ruleFromJson)}:{Environment.NewLine}" +
                                        $"{ruleFromJson.ExpressionDebugView()}");
            var ruleResult2 = ruleFromJson.Execute(searchValue);

            _testOutputHelper.WriteLine($"expected: {expectedValue} - actual: {ruleResult2}");
            ruleResult2.Should().Be(expectedValue);
        }
        public void ConditionalOut(int evenOddValue, string expectedResult)
        {
            var evenOrOddResult = new ConditionalFuncRule <int, string>
            {
                ConditionRule = new ExpressionFuncRule <int, bool>(i => i % 2 == 0),
                TrueRule      = new ExpressionFuncRule <int, string>(i => string.Format($"{i} is even")),
                FalseRule     = new ExpressionFuncRule <int, string>(i => string.Format($"{i} is odd"))
            };

            var compileResult = evenOrOddResult.Compile();

            compileResult.Should().BeTrue();
            _testOutputHelper.WriteLine($"{nameof(evenOrOddResult)}:{Environment.NewLine}" +
                                        $"{evenOrOddResult.ExpressionDebugView()}");

            var ruleResult = evenOrOddResult.Execute(evenOddValue);

            _testOutputHelper.WriteLine($"expected: {expectedResult} - actual: {ruleResult}");
            ruleResult.Should().BeEquivalentTo(expectedResult);
        }