Esempio n. 1
0
        public void EvaluateMultipleSetExpressionUsingDynamicObject()
        {
            DynamicObject dynobj = new DynamicObject();

            MultipleSetExpression expression = new MultipleSetExpression(new ConstantExpression(dynobj), new string[] { "FirstName", "LastName" }, new IExpression[] { new ConstantExpression("John"), new ConstantExpression("Doe") });

            object result = expression.Evaluate(new BindingEnvironment());

            Assert.IsNotNull(result);
            Assert.IsTrue(result == dynobj);

            Assert.AreEqual("John", dynobj.GetValue("FirstName"));
            Assert.AreEqual("Doe", dynobj.GetValue("LastName"));
        }
Esempio n. 2
0
        public void ParseNewExpressionWithDynamicObjectMemberNotation()
        {
            IExpression expression = ParseExpression("new { var Name = \"Adam\"; var Age = 800;}");

            Assert.IsNotNull(expression);
            Assert.IsInstanceOfType(expression, typeof(MultipleSetExpression));

            MultipleSetExpression msetexp = (MultipleSetExpression)expression;

            Assert.IsNotNull(msetexp.LeftObject);
            Assert.IsInstanceOfType(msetexp.LeftObject, typeof(NewExpression));
            Assert.AreEqual(2, msetexp.PropertyNames.Length);
            Assert.AreEqual("Name", msetexp.PropertyNames[0]);
            Assert.AreEqual("Age", msetexp.PropertyNames[1]);
        }
Esempio n. 3
0
        public void ParseNewExpressionWithPropertyInitialization()
        {
            IExpression expression = ParseExpression("new System.Data.SqlClient.SqlConnection() { ConnectionString = \"foo\", CommandText = \"bar\"}");

            Assert.IsNotNull(expression);
            Assert.IsInstanceOfType(expression, typeof(MultipleSetExpression));

            MultipleSetExpression msetexp = (MultipleSetExpression)expression;

            Assert.IsNotNull(msetexp.LeftObject);
            Assert.IsInstanceOfType(msetexp.LeftObject, typeof(NewExpression));
            Assert.AreEqual(2, msetexp.PropertyNames.Length);
            Assert.AreEqual("ConnectionString", msetexp.PropertyNames[0]);
            Assert.AreEqual("CommandText", msetexp.PropertyNames[1]);
        }