Exemplo n.º 1
0
        public void SpelExpressionArrayWithVariables()
        {
            var parser         = new SpelExpressionParser();
            var spelExpression = parser.ParseExpression("#anArray[0] eq 1");
            var ctx            = new StandardEvaluationContext();
            var hmap           = new Dictionary <string, object>()
            {
                { "anArray", new int[] { 1, 2, 3 } }
            };

            ctx.SetVariables(hmap);

            var result = spelExpression.GetValue <bool>(ctx);

            Assert.True(result);
        }
Exemplo n.º 2
0
        public void SpelExpressionListIndexAccessWithVariables()
        {
            var parser         = new SpelExpressionParser();
            var spelExpression = parser.ParseExpression("#aList[0] eq 'one'");
            var ctx            = new StandardEvaluationContext();
            var hmap           = new Dictionary <string, object>()
            {
                { "aList", new List <string>()
                  {
                      "one", "two", "three"
                  } }
            };

            ctx.SetVariables(hmap);
            var result = spelExpression.GetValue <bool>(ctx);

            Assert.True(result);
        }
Exemplo n.º 3
0
        public void SpelExpressionMapWithVariables()
        {
            var parser         = new SpelExpressionParser();
            var spelExpression = parser.ParseExpression("#aMap['one'] eq 1");
            var ctx            = new StandardEvaluationContext();
            var hmap           = new Dictionary <string, object>()
            {
                { "aMap", new Dictionary <string, int>()
                  {
                      { "one", 1 }, { "two", 2 }, { "three", 3 }
                  } }
            };

            ctx.SetVariables(hmap);

            var result = spelExpression.GetValue <bool>(ctx);

            Assert.True(result);
        }