Пример #1
0
        public void ConditionalRuleToUpdateNameToSomethingElse()
        {
            var conditionalIfThElRule = new ConditionalIfThElActionRule <Game>
            {
                ConditionRule = new MethodCallRule <Game, bool>
                {
                    ObjectToCallMethodOn = "Name",
                    MethodToCall         = "Equals",
                    MethodParameters     =
                    {
                        new ConstantRule <string>           {
                            Value = "some name"
                        },
                        new ConstantRule <StringComparison> {
                            Value = "CurrentCultureIgnoreCase"
                        }
                    }
                },
                TrueRule = new UpdateValueRule <Game>
                {
                    ObjectToUpdate = "Name",
                    SourceDataRule = new ConstantRule <string> {
                        Value = "true name"
                    }
                },
                FalseRule = new UpdateValueRule <Game>
                {
                    ObjectToUpdate = "Name",
                    SourceDataRule = new ConstantRule <string> {
                        Value = "false name"
                    }
                }
            };

            var compileResult = conditionalIfThElRule.Compile();

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

            var game = new Game {
                Name = "some name"
            };

            _testOutputHelper.WriteLine($"before game.Name: {game.Name}");
            conditionalIfThElRule.Execute(game);
            _testOutputHelper.WriteLine($"after game.Name: {game.Name}");
            game.Name.Should().Be("true name");

            conditionalIfThElRule.Execute(game);
            _testOutputHelper.WriteLine($"after after game.Name: {game.Name}");
            game.Name.Should().Be("false name");
        }
Пример #2
0
        public void ConditionalOutput(int evenOddValue)
        {
            var evenOrOddOutput = new ConditionalIfThElActionRule <int>
            {
                ConditionRule = new ExpressionFuncRule <int, bool>(i => i % 2 == 0),
                TrueRule      = new ExpressionActionRule <int>(i => _testOutputHelper.WriteLine($"{i} is even")),
                FalseRule     = new ExpressionActionRule <int>(i => _testOutputHelper.WriteLine($"{i} is odd"))
            };

            var compileResult = evenOrOddOutput.Compile();

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

            evenOrOddOutput.Execute(evenOddValue);
        }