Example #1
0
        public void GetNativeMethod()
        {
            AttributeExpression expression  = new AttributeExpression(new ConstantExpression(1), "GetType");
            BindingEnvironment  environment = new BindingEnvironment();

            var result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(MethodInfo));
        }
Example #2
0
        public void EvaluateAttributeExpressionOnClassProperty()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("Calculator"), "Value");
            BindingEnvironment  environment = new BindingEnvironment();

            environment.SetValue("Calculator", typeof(Calculator));

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result);
        }
Example #3
0
        public void EvaluateAttributeExpressionOnNativeObjectProperty()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("adam"), "FirstName");
            BindingEnvironment  environment = new BindingEnvironment();

            environment.SetValue("adam", new Person()
            {
                FirstName = "Adam"
            });

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.AreEqual("Adam", result);
        }
Example #4
0
        public void EvaluateAttributeExpression()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("module"), "foo");
            BindingEnvironment  environment = new BindingEnvironment();
            BindingEnvironment  modenv      = new BindingEnvironment();

            modenv.SetValue("foo", "bar");
            environment.SetValue("module", modenv);

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.AreEqual("bar", result);
            Assert.IsNotNull(expression.Expression);
            Assert.AreEqual("foo", expression.Name);
        }
Example #5
0
        public void RaiseWhenEvaluateAttributeExpression()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("module"), "spam");
            BindingEnvironment  environment = new BindingEnvironment();
            BindingEnvironment  modenv      = new BindingEnvironment();

            environment.SetValue("module", modenv);

            try
            {
                expression.Evaluate(environment);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(AttributeError));
                Assert.AreEqual("'module' object has no attribute 'spam'", ex.Message);
            }
        }