コード例 #1
0
        public virtual void EvaluateAndAskForReturnType(string expression, object expectedValue, Type expectedResultType)
        {
            var expr = _parser.ParseExpression(expression);

            Assert.NotNull(expr);
            if (DEBUG)
            {
                SpelUtilities.PrintAbstractSyntaxTree(Console.Out, expr);
            }

            var value = expr.GetValue(_context, expectedResultType);

            if (value == null)
            {
                if (expectedValue == null)
                {
                    return;  // no point doing other checks
                }

                Assert.True(expectedValue == null, "Expression returned null value, but expected '" + expectedValue + "'");
            }

            var resultType = value.GetType();

            Assert.Equal(expectedResultType, resultType);
            Assert.Equal(expectedValue, value);
        }
コード例 #2
0
ファイル: SetValueTests.cs プロジェクト: kimbell/Steeltoe
        protected void SetValue(string expression, object value, object expectedValue)
        {
            try
            {
                var e = parser.ParseExpression(expression);
                Assert.NotNull(e);
                if (DEBUG)
                {
                    SpelUtilities.PrintAbstractSyntaxTree(Console.Out, e);
                }

                var lContext = TestScenarioCreator.GetTestEvaluationContext();
                Assert.True(e.IsWritable(lContext));
                e.SetValue(lContext, value);
                var a = expectedValue;
                var b = e.GetValue(lContext);
                Assert.Equal(b, a);
            }
            catch (EvaluationException ex)
            {
                throw new Exception("Unexpected Exception: " + ex.Message, ex);
            }
            catch (ParseException ex)
            {
                throw new Exception("Unexpected Exception: " + ex.Message, ex);
            }
        }
コード例 #3
0
        protected virtual void ParseAndCheckError(string expression, SpelMessage expectedMessage, params object[] otherProperties)
        {
            var ex = Assert.Throws <SpelParseException>(() =>
            {
                var expr = _parser.ParseExpression(expression);
                if (DEBUG)
                {
                    SpelUtilities.PrintAbstractSyntaxTree(Console.Out, expr);
                }
            });

            Assert.Equal(expectedMessage, ex.MessageCode);
            if (otherProperties != null && otherProperties.Length != 0)
            {
                // first one is expected position of the error within the string
                var pos = (int)otherProperties[0];
                Assert.Equal(pos, ex.Position);
                if (otherProperties.Length > 1)
                {
                    // Check inserts match
                    var inserts = ex.Inserts;
                    Assert.True(inserts.Length >= otherProperties.Length - 1);
                    var expectedInserts = new object[inserts.Length];
                    Array.Copy(otherProperties, 1, expectedInserts, 0, expectedInserts.Length);
                    Assert.Equal(expectedInserts.Length, inserts.Length);
                    for (var i = 0; i < inserts.Length; i++)
                    {
                        Assert.Equal(expectedInserts[i], inserts[i]);
                    }
                }
            }
        }
コード例 #4
0
ファイル: SetValueTests.cs プロジェクト: kimbell/Steeltoe
        protected void SetValueExpectError(string expression, object value)
        {
            var e = parser.ParseExpression(expression);

            Assert.NotNull(e);
            if (DEBUG)
            {
                SpelUtilities.PrintAbstractSyntaxTree(Console.Out, e);
            }

            var lContext = TestScenarioCreator.GetTestEvaluationContext();

            Assert.Throws <SpelEvaluationException>(() => e.SetValue(lContext, value));
        }
コード例 #5
0
        public virtual void Evaluate(string expression, object expectedValue, Type expectedClassOfResult, bool shouldBeWritable)
        {
            var expr = _parser.ParseExpression(expression);

            Assert.NotNull(expr);
            if (DEBUG)
            {
                SpelUtilities.PrintAbstractSyntaxTree(Console.Out, expr);
            }

            var value = expr.GetValue(_context);

            if (value == null)
            {
                if (expectedValue == null)
                {
                    return;  // no point doing other checks
                }

                Assert.True(expectedValue == null, "Expression returned null value, but expected '" + expectedValue + "'");
            }

            var resultType = value.GetType();

            if (expectedValue is string)
            {
                Assert.Equal(expectedValue, AbstractExpressionTests.StringValueOf(value));
            }
            else
            {
                Assert.Equal(expectedValue, value);
            }

            Assert.Equal(expectedClassOfResult, resultType);
            Assert.Equal(shouldBeWritable, expr.IsWritable(_context));
        }