public static void TestMetaObject(DynamicMetaObject target, ExpressionType[] testExpressions, bool isValid = true)
            {
                foreach (ExpressionType expType in testExpressions)
                {
                    UnaryOperationBinder binder = new TestUnaryOperationBinder(expType);
                    DynamicMetaObject    result = target.BindUnaryOperation(binder);
                    Assert.IsNotNull(result);

                    UnaryExpression expression = result.Expression as UnaryExpression;
                    Assert.IsNotNull(expression);

                    ExpressionType expectedType = isValid ? expType : ExpressionType.Throw;
                    Assert.AreEqual <ExpressionType>(expectedType, expression.Operand.NodeType);
                }
            }
        public void BindUnaryOperationTest()
        {
            JsonValue         value;
            DynamicMetaObject target;

            value  = new JsonPrimitive(AnyInstance.AnyInt);
            target = GetJsonValueDynamicMetaObject(value);

            TestUnaryOperationBinder.TestBindParams(target);
            TestUnaryOperationBinder.TestMetaObject(target, TestUnaryOperationBinder.NumberOperations);

            value  = new JsonPrimitive(AnyInstance.AnyBool);
            target = GetJsonValueDynamicMetaObject(value);

            TestUnaryOperationBinder.TestMetaObject(target, TestUnaryOperationBinder.BooleanOperations);
        }
        public void InvalidBindUnaryOperationTest()
        {
            JsonValue[] values =
            {
                AnyInstance.AnyJsonObject,
                AnyInstance.AnyJsonArray,
                AnyInstance.AnyInt,
                AnyInstance.DefaultJsonValue
            };

            foreach (JsonValue value in values)
            {
                DynamicMetaObject target = GetJsonValueDynamicMetaObject(value);

                TestUnaryOperationBinder.TestMetaObject(target, TestUnaryOperationBinder.UnsupportedOperations, false);

                if (!(value is JsonPrimitive))
                {
                    TestUnaryOperationBinder.TestMetaObject(target, TestUnaryOperationBinder.NumberOperations, false);
                    TestUnaryOperationBinder.TestMetaObject(target, TestUnaryOperationBinder.BooleanOperations, false);
                }
            }
        }
            public static void TestMetaObject(DynamicMetaObject target, ExpressionType[] testExpressions, bool isValid = true)
            {
                foreach (ExpressionType expType in testExpressions)
                {
                    UnaryOperationBinder binder = new TestUnaryOperationBinder(expType);
                    DynamicMetaObject result = target.BindUnaryOperation(binder);
                    Assert.IsNotNull(result);

                    UnaryExpression expression = result.Expression as UnaryExpression;
                    Assert.IsNotNull(expression);

                    ExpressionType expectedType = isValid ? expType : ExpressionType.Throw;
                    Assert.AreEqual<ExpressionType>(expectedType, expression.Operand.NodeType);
                }
            }
 public static void TestBindParams(DynamicMetaObject target)
 {
     UnaryOperationBinder binder = new TestUnaryOperationBinder(ExpressionType.Negate);
     ExceptionTestHelper.ExpectException<ArgumentNullException>(() => { var result = target.BindUnaryOperation(null); });
 }
            public static void TestBindParams(DynamicMetaObject target)
            {
                UnaryOperationBinder binder = new TestUnaryOperationBinder(ExpressionType.Negate);

                ExceptionTestHelper.ExpectException <ArgumentNullException>(() => { var result = target.BindUnaryOperation(null); });
            }