コード例 #1
0
            public static void TestBindParams(DynamicMetaObject target)
            {
                GetIndexBinder binder         = new TestGetIndexBinder();
                Expression     typeExpression = Expression.Parameter(typeof(int));

                DynamicMetaObject[] indexes =
                {
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 0),
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 1),
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 2)
                };

                ExceptionTestHelper.ExpectException <ArgumentNullException>(() => { var result = target.BindGetIndex(null, indexes); });
                ExceptionTestHelper.ExpectException <ArgumentNullException>(() => { var result = target.BindGetIndex(binder, null); });

                DynamicMetaObject[][] invalidIndexesParam =
                {
                    indexes,
                    new DynamicMetaObject[] { new DynamicMetaObject(typeExpression,BindingRestrictions.Empty,                                                         null) },
                    new DynamicMetaObject[] { null },
                    new DynamicMetaObject[] { }
                };

                foreach (DynamicMetaObject[] indexesParam in invalidIndexesParam)
                {
                    DynamicMetaObject metaObj = target.BindGetIndex(binder, indexesParam);

                    Expression <Action> expression = Expression.Lambda <Action>(Expression.Block(metaObj.Expression), new ParameterExpression[] { });
                    ExceptionTestHelper.ExpectException <ArgumentException>(() => { expression.Compile().Invoke(); }, NonSingleNonNullIndexNotSupported);
                }
            }
コード例 #2
0
        public void BindGetIndexTest()
        {
            JsonValue value = AnyInstance.AnyJsonArray;

            DynamicMetaObject target = GetJsonValueDynamicMetaObject(value);

            TestGetIndexBinder.TestBindParams(target);

            foreach (KeyValuePair <string, JsonValue> pair in value)
            {
                TestGetIndexBinder.TestMetaObject(target, int.Parse(pair.Key));
            }
        }
コード例 #3
0
            public static void TestMetaObject(DynamicMetaObject target, int index, bool isValid = true)
            {
                string expectedMethodSignature = "System.Json.JsonValue GetValue(Int32)";

                GetIndexBinder binder = new TestGetIndexBinder();

                DynamicMetaObject[] indexes = { new DynamicMetaObject(Expression.Parameter(typeof(int)), BindingRestrictions.Empty, index) };

                DynamicMetaObject result = target.BindGetIndex(binder, indexes);

                Assert.IsNotNull(result);

                MethodCallExpression expression = result.Expression as MethodCallExpression;

                Assert.IsNotNull(expression);
                Assert.AreEqual <string>(expectedMethodSignature, expression.Method.ToString());
            }
コード例 #4
0
            public static void TestMetaObject(DynamicMetaObject target, int index, bool isValid = true)
            {
                string expectedMethodSignature = "System.Json.JsonValue GetValue(Int32)";

                GetIndexBinder binder = new TestGetIndexBinder();
                DynamicMetaObject[] indexes = {  new DynamicMetaObject(Expression.Parameter(typeof(int)), BindingRestrictions.Empty, index) };

                DynamicMetaObject result = target.BindGetIndex(binder, indexes);
                Assert.IsNotNull(result);

                MethodCallExpression expression = result.Expression as MethodCallExpression;
                Assert.IsNotNull(expression);
                Assert.AreEqual<string>(expectedMethodSignature, expression.Method.ToString());
            }
コード例 #5
0
            public static void TestBindParams(DynamicMetaObject target)
            {
                GetIndexBinder binder = new TestGetIndexBinder();
                Expression typeExpression = Expression.Parameter(typeof(int));

                DynamicMetaObject[] indexes =
                {
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 0),
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 1),
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 2)
                };

                ExceptionTestHelper.ExpectException<ArgumentNullException>(() => { var result = target.BindGetIndex(null, indexes); });
                ExceptionTestHelper.ExpectException<ArgumentNullException>(() => { var result = target.BindGetIndex(binder, null); });

                DynamicMetaObject[][] invalidIndexesParam =
                {
                    indexes,
                    new DynamicMetaObject[] { new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, null) },
                    new DynamicMetaObject[] { null },
                    new DynamicMetaObject[] { }
                };

                foreach (DynamicMetaObject[] indexesParam in invalidIndexesParam)
                {
                    DynamicMetaObject metaObj = target.BindGetIndex(binder, indexesParam);

                    Expression<Action> expression = Expression.Lambda<Action>(Expression.Block(metaObj.Expression), new ParameterExpression[] { });
                    ExceptionTestHelper.ExpectException<ArgumentException>(() => { expression.Compile().Invoke(); }, NonSingleNonNullIndexNotSupported);
                }
            }