Пример #1
0
        public void UpdatePropertyStingWithDifferentValue()
        {
            var game = new Game {
                Name = "game name"
            };
            var nameChangeRule = new UpdateValueRule <Game, string>
            {
                ObjectToUpdate = "Name"
            };

            var compileResult = nameChangeRule.Compile();

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

            _testOutputHelper.WriteLine($"before game.Name: {game.Name}");
            nameChangeRule.UpdateFieldOrPropertyValue(game, "new name");
            game.Name.Should().Be("new name");
            _testOutputHelper.WriteLine($"after game.Name: {game.Name}");
        }
Пример #2
0
        public void UpdatePropertyFromAnotherRuleToAndFromJson()
        {
            var game = new Game {
                Name = "game name"
            };
            var rule = new UpdateValueRule <Game>
            {
                ObjectToUpdate = "Name",
                SourceDataRule = new ConstantRule <string> {
                    Value = "name from constant rule"
                }
            };

            var compileResult = rule.Compile();

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

            _testOutputHelper.WriteLine($"before game.Name: {game.Name}");
            rule.UpdateFieldOrPropertyValue(game);
            game.Name.Should().Be("name from constant rule");
            _testOutputHelper.WriteLine($"after game.Name: {game.Name}");

            // 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()}");

            game.Name = "game name";
            ((UpdateValueRule <Game>)ruleFromJson).UpdateFieldOrPropertyValue(game);
            game.Name.Should().Be("name from constant rule");
        }
Пример #3
0
        public void UpdatePropertyFromAnotherRule()
        {
            var game = new Game {
                Name = "game name"
            };
            var nameChangeRule = new UpdateValueRule <Game>
            {
                ObjectToUpdate = "Name",
                SourceDataRule = new ConstantRule <string> {
                    Value = "name from constant rule"
                }
            };

            var compileResult = nameChangeRule.Compile();

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

            _testOutputHelper.WriteLine($"before game.Name: {game.Name}");
            nameChangeRule.UpdateFieldOrPropertyValue(game);
            game.Name.Should().Be("name from constant rule");
            _testOutputHelper.WriteLine($"after game.Name: {game.Name}");
        }