/// <summary>
        /// Creates a <c>LeafExpression</c> capable of evaluating JSON using the operator specified in the JSON rule.
        /// </summary>
        /// <returns>The LeafExpression.</returns>
        public override Expression ToExpression()
        {
            LeafExpressionOperator leafOperator = null;

            if (this.Exists != null)
            {
                leafOperator = new ExistsOperator(Exists.Value, isNegative: false);
            }
            else if (this.HasValue != null)
            {
                leafOperator = new HasValueOperator(HasValue.Value, isNegative: false);
            }
            else if (this.Is != null || this.NotEquals != null)
            {
                leafOperator = new EqualsOperator(
                    specifiedValue: this.Is ?? this.NotEquals,
                    isNegative: this.NotEquals != null);
            }

            if (leafOperator != null)
            {
                return(new LeafExpression(this.ResourceType, this.Path, leafOperator));
            }

            throw new NotImplementedException();
        }
Example #2
0
        public void EvaluateExpression_PropertyDoesNotExist_ExistsExpressionIsFalse()
        {
            // {"Exists": true} is false for null JToken
            var existsOperator = new ExistsOperator(true, isNegative: false);

            Assert.IsFalse(existsOperator.EvaluateExpression(null));

            // {"Exists": false} is true for null JToken
            existsOperator = new ExistsOperator(false, isNegative: false);
            Assert.IsTrue(existsOperator.EvaluateExpression(null));
        }
Example #3
0
        public void EvaluateExpression_PropertyIsObject_ExistsExpressionIsTrue()
        {
            var jToken = ToJToken(new { });

            // {"Exists": true} is true
            var existsOperator = new ExistsOperator(true, isNegative: false);

            Assert.IsTrue(existsOperator.EvaluateExpression(jToken));

            // {"Exists": false} is false
            existsOperator = new ExistsOperator(false, isNegative: false);
            Assert.IsFalse(existsOperator.EvaluateExpression(jToken));
        }
Example #4
0
 private static void ExistsValidation(ExistsOperator existsOperator, bool operatorValue)
 {
     Assert.AreEqual(operatorValue, existsOperator.EffectiveValue);
     Assert.IsFalse(existsOperator.IsNegative);
 }