Пример #1
0
        public void TwoInOneOutParameterExpressionTest2()
        {
            var ruleFindCountriesNotInOther = new ExpressionFuncRule <Game, Game, IEnumerable <Player> >((g1, g2) =>
                                                                                                         g1.Players.Except(g2.Players, new PlayerCountryEqualityComparer())
                                                                                                         );
            var compileResult = ruleFindCountriesNotInOther.Compile();

            _testOutputHelper.WriteLine($"{nameof(ruleFindCountriesNotInOther)}:{Environment.NewLine}" +
                                        $"{ruleFindCountriesNotInOther.ExpressionDebugView()}");

            compileResult.Should().BeTrue();
            var executeResult = ruleFindCountriesNotInOther.Execute(_game1, _game2).ToList();

            executeResult.Should().BeOfType(typeof(List <Player>));
            _testOutputHelper.WriteLine(".............g1.except(g2)....");
            executeResult.ForEach(p => _testOutputHelper.WriteLine($"country: {p.Country.CountryCode}"));

            executeResult = ruleFindCountriesNotInOther.Execute(_game2, _game1).ToList();
            _testOutputHelper.WriteLine(".............g2.except(g1)....");
            executeResult.ForEach(p => _testOutputHelper.WriteLine($"country: {p.Country.CountryCode}"));
        }
Пример #2
0
        public void OneOutParameterExpressionTest()
        {
            var ruleReturningAFixedValue = new ExpressionFuncRule <int>(() => int.MaxValue);
            var compileResult            = ruleReturningAFixedValue.Compile();

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

            var executeResult = ruleReturningAFixedValue.Execute();

            executeResult.Should().BeOfType(typeof(int)).And.Be(int.MaxValue);
        }
Пример #3
0
        public void OneInOneOutParameterExpressionTest()
        {
            // g => IIF(((g == null) OrElse (g.Players == null)), 0, g.Players.Count)
            var ruleReturningCountOfPlayers = new ExpressionFuncRule <Game, int>(
                g => (g == null || g.Players == null) ? 0 : g.Players.Count);
            var compileResult = ruleReturningCountOfPlayers.Compile();

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

            var executeResult = ruleReturningCountOfPlayers.Execute(_game1);

            executeResult.Should().BeOfType(typeof(int)).And.Be(_game1.Players.Count);
        }
Пример #4
0
        public void TwoInOneOutParameterExpressionTest()
        {
            var ruleReturningTotalCountOfPlayers = new ExpressionFuncRule <Game, Game, int>((g1, g2) =>
                                                                                            ((g1 == null || g1.Players == null) ? 0 : g1.Players.Count) +
                                                                                            ((g2 == null || g2.Players == null) ? 0 : g2.Players.Count)
                                                                                            );
            var compileResult = ruleReturningTotalCountOfPlayers.Compile();

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

            var executeResult = ruleReturningTotalCountOfPlayers.Execute(_game1, _game2);

            executeResult.Should().BeOfType(typeof(int)).And.Be(_game1.Players.Count + _game2.Players.Count);
        }