public void EvaluateNameExpression() { NameExpression expression = new NameExpression("foo"); BindingEnvironment environment = new BindingEnvironment(); environment.SetValue("foo", "bar"); Assert.AreEqual("bar", expression.Evaluate(environment)); }
public void EvaluateNameWithNull() { NameExpression expression = new NameExpression("foo"); BindingEnvironment environment = new BindingEnvironment(); environment.SetValue("foo", null); Assert.IsNull(expression.Evaluate(environment)); }
public void RaiseIfNameIsUndefined() { NameExpression expression = new NameExpression("foo"); BindingEnvironment environment = new BindingEnvironment(); try { expression.Evaluate(environment); Assert.Fail("Exception expected"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(NameError)); Assert.AreEqual("name 'foo' is not defined", ex.Message); } }
public void CreateAndEvaluateParameterExpressionWithNameAndDefaultExpression() { var environment = new BindingEnvironment(); environment.SetValue("b", 1); var defaultExpression = new NameExpression("b"); var expression = new ParameterExpression("a", defaultExpression, false); var result = expression.Evaluate(environment); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(Parameter)); var param = (Parameter)result; Assert.AreEqual("a", expression.Name); Assert.AreEqual(defaultExpression, expression.DefaultExpression); Assert.IsFalse(expression.IsList); Assert.AreEqual("a", param.Name); Assert.AreEqual(1, param.DefaultValue); Assert.IsFalse(param.IsList); }