public void CallCreateGameStaticMethod3UsingFactory()
        {
            //var game = Game.CreateGame("game", "description", 1, true);
            var methodParams = new List <Rule>
            {
                ConstantRulesFactory.CreateConstantRule <string>("game"),
                ConstantRulesFactory.CreateConstantRule <string>("description"),
                ConstantRulesFactory.CreateConstantRule <int>("1"),
                ConstantRulesFactory.CreateConstantRule <bool>("true")
            };
            var rule = MethodCallRulesFactory.CreateStaticMethodCallRule <Game>("CreateGame",
                                                                                "ModelForUnitTests.Game", methodParams);

            var compileResult = rule.Compile();

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

            var game = rule.Execute();

            game.Should().NotBeNull();
            game.Name.Should().Be("game");
            _testOutputHelper.WriteLine($"{game}");
        }
예제 #2
0
        public void ReturnsNewOrUpdatedGameUsingFactory()
        {
            var nullGame          = ConstantRulesFactory.CreateConstantRule <Game>("null");
            var nullGameCheckRule =
                ValidationRulesFactory.CreateValidationRule <Game>(LogicalOperatorAtTheRootLevel.Equal, nullGame);

            var newGameRule = MethodCallRulesFactory.CreateStaticMethodCallRule <Game>("CreateGame", "ModelForUnitTests.Game", null);

            var selfReturnRule = SelfReturnRuleFactory.CreateSelfReturnRule <Game>();
            var gameObjectRule = ConditionalRulesFactory.CreateConditionalFuncRule <Game, Game>(nullGameCheckRule, newGameRule,
                                                                                                selfReturnRule);

            var assignRule = UpdateValueRulesFactory.CreateUpdateValueRule <Game>(gameObjectRule);

            var nameConstRule         = ConstantRulesFactory.CreateConstantRule <string>("some fancy name");
            var nameChangeRule        = UpdateValueRulesFactory.CreateUpdateValueRule <Game>(g => g.Name, nameConstRule);
            var rankConstRule         = ConstantRulesFactory.CreateConstantRule <int>("1000");
            var rankingChangeRule     = UpdateValueRulesFactory.CreateUpdateValueRule <Game>(g => g.Ranking, rankConstRule);
            var descConstRule         = ConstantRulesFactory.CreateConstantRule <string>("some cool description");
            var descriptionChangeRule = UpdateValueRulesFactory.CreateUpdateValueRule <Game>(g => g.Description, descConstRule);

            IList <Rule> rules = new List <Rule>
            {
                assignRule,
                nameChangeRule,
                rankingChangeRule,
                descriptionChangeRule,
                selfReturnRule
            };
            var blockRule = BlockRulesFactory.CreateFuncBlockRule <Game, Game>(rules);

            var compileResult = blockRule.Compile();

            compileResult.Should().BeTrue();

            var game = blockRule.Execute(null);

            game.Name.Should().Be("some fancy name");
            game.Ranking.Should().Be(1000);
            game.Description.Should().Be("some cool description");
            game.Rating.Should().BeNullOrEmpty();
            _testOutputHelper.WriteLine($"{game}");

            var newGame = new Game {
                Rating = "high"
            };

            // newGame is not same as game object
            ReferenceEquals(game, newGame).Should().BeFalse();
            game = blockRule.Execute(newGame);
            // this call shall return the same newGame object with updated values
            ReferenceEquals(game, newGame).Should().BeTrue();
            game.Rating.Should().Be("high");
            _testOutputHelper.WriteLine($"newGame: {game}");
        }
        public void CallCreateGameStaticMethodUsingFactory()
        {
            //var game = Game.CreateGame();
            var rule = MethodCallRulesFactory.CreateStaticMethodCallRule <Game>("CreateGame", "ModelForUnitTests.Game", null);

            var compileResult = rule.Compile();

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

            var game = rule.Execute();

            game.Should().NotBeNull();
        }