public void PropertyAccessWithInstanceMethodResolver() { var context = SimpleEvaluationContext.ForReadOnlyDataBinding().WithInstanceMethods().Build(); var target = new Person("p1"); Assert.Equal("1", parser.ParseExpression("Name.Substring(1)").GetValue(context, target)); }
public void PropertyAccessWithoutMethodResolver() { var context = SimpleEvaluationContext.ForReadOnlyDataBinding().Build(); var target = new Person("p1"); Assert.Throws <SpelEvaluationException>(() => parser.ParseExpression("Name.Substring(1)").GetValue(context, target)); }
public void PropertyAccessWithArrayIndexOutOfBounds() { var context = SimpleEvaluationContext.ForReadOnlyDataBinding().Build(); var expression = parser.ParseExpression("StringArrayOfThreeItems[3]"); var ex = Assert.Throws <SpelEvaluationException>(() => expression.GetValue(context, new Inventor())); Assert.Equal(SpelMessage.ARRAY_INDEX_OUT_OF_BOUNDS, ex.MessageCode); }
public void PropertyAccessWithInstanceMethodResolverAndTypedRootObject() { var target = new Person("p1"); var context = SimpleEvaluationContext.ForReadOnlyDataBinding(). WithInstanceMethods().WithTypedRootObject(target, typeof(object)).Build(); Assert.Equal("1", parser.ParseExpression("Name.Substring(1)").GetValue(context, target)); Assert.Same(target, context.RootObject.Value); Assert.Equal(typeof(object), context.RootObject.TypeDescriptor); }
public void PropertyReadOnly() { var context = SimpleEvaluationContext.ForReadOnlyDataBinding().Build(); var expr = parser.ParseExpression("Name"); var target = new Person("p1"); Assert.Equal("p1", expr.GetValue(context, target)); target.Name = "p2"; Assert.Equal("p2", expr.GetValue(context, target)); Assert.Throws <SpelEvaluationException>(() => parser.ParseExpression("Name='p3'").GetValue(context, target)); }
public void NoGetClassAccess() { var context = SimpleEvaluationContext.ForReadOnlyDataBinding().Build(); Assert.Throws <SpelEvaluationException>(() => parser.ParseExpression("'a'.GetType().Name").GetValue(context)); }