/// <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();
        }
Exemplo n.º 2
0
        public void EvaluateExpression_PropertyDoesNotExist_HasValueIsFalse()
        {
            // {"HasValue": true} is false
            var hasValueOperator = new HasValueOperator(true, isNegative: false);

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

            // {"HasValue": false} is true
            hasValueOperator = new HasValueOperator(false, isNegative: false);
            Assert.IsTrue(hasValueOperator.EvaluateExpression(null));
        }
Exemplo n.º 3
0
        public void EvaluateExpression_PropertyHasNullOrEmptyValue_HasValueIsFalse(object jTokenValue)
        {
            var jToken = ToJToken(jTokenValue);

            // {"HasValue": true} is false
            var hasValueOperator = new HasValueOperator(true, isNegative: false);

            Assert.IsFalse(hasValueOperator.EvaluateExpression(jToken));

            // {"HasValue": false} is true
            hasValueOperator = new HasValueOperator(false, isNegative: false);
            Assert.IsTrue(hasValueOperator.EvaluateExpression(jToken));
        }
Exemplo n.º 4
0
        public void EvaluateExpression_PropertyIsObject_HasValueIsTrue()
        {
            var jToken = ToJToken(new { });

            // {"HasValue": true} is true
            var hasValueOperator = new HasValueOperator(true, isNegative: false);

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

            // {"HasValue": false} is false
            hasValueOperator = new HasValueOperator(false, isNegative: false);
            Assert.IsFalse(hasValueOperator.EvaluateExpression(jToken));
        }
Exemplo n.º 5
0
 private static void HasValueValidation(HasValueOperator hasValueOperator, bool operatorValue)
 {
     Assert.AreEqual(operatorValue, hasValueOperator.EffectiveValue);
     Assert.IsFalse(hasValueOperator.IsNegative);
 }