Esempio n. 1
0
        public void TestGetArrayProperty()
        {
            var list = AnyValueArray.FromValues(123, "ABC");

            var value = ObjectReader.GetProperty(list, "3");

            Assert.Null(value);

            value = ObjectReader.GetProperty(list, "0");
            Assert.Equal(123, value);

            value = ObjectReader.GetProperty(list, "1");
            Assert.Equal("ABC", value);

            var array = new object[] { 123, "ABC" };

            value = ObjectReader.GetProperty(array, "3");
            Assert.Null(value);

            value = ObjectReader.GetProperty(array, "0");
            Assert.Equal(123, value);

            value = ObjectReader.GetProperty(array, "1");
            Assert.Equal("ABC", value);
        }
Esempio n. 2
0
        /// <summary>
        /// Validates a given value against this rule.
        /// </summary>
        /// <param name="path">a dot notation path to the value.</param>
        /// <param name="schema">a schema this rule is called from</param>
        /// <param name="value">a value to be validated.</param>
        /// <param name="results">a list with validation results to add new results.</param>
        public void Validate(string path, Schema schema, object value, List <ValidationResult> results)
        {
            var name  = path ?? "value";
            var found = new List <string>();

            foreach (var property in _properties)
            {
                var propertyValue = ObjectReader.GetProperty(value, property);
                if (propertyValue != null)
                {
                    found.Add(property);
                }
            }

            if (found.Count == 0)
            {
                results.Add(
                    new ValidationResult(
                        path,
                        ValidationResultType.Error,
                        "VALUE_NULL",
                        name + " must have at least one property from " + _properties,
                        _properties,
                        null
                        )
                    );
            }
        }
Esempio n. 3
0
        public void TestGetObjectProperty()
        {
            var obj = new TestClass();

            var value = ObjectReader.GetProperty(obj, "_privateField");

            Assert.Null(value);

            value = ObjectReader.GetProperty(obj, "PublicField");
            Assert.Equal("ABC", value);

            value = ObjectReader.GetProperty(obj, "PublicProp");
            Assert.NotNull(value);
        }
Esempio n. 4
0
        public void TestGetMapProperty()
        {
            var map = AnyValueMap.FromTuples(
                "key1", 123,
                "key2", "ABC"
                );

            var key3Value = ObjectReader.GetProperty(map, "key3");

            Assert.Null(key3Value);

            var key1Value = ObjectReader.GetProperty(map, "Key1");

            Assert.Equal(123, key1Value);

            var key2Value = ObjectReader.GetProperty(map, "KEY2");

            Assert.Equal("ABC", key2Value);
        }
        public void Validate(string path, Schema schema, object value, List <ValidationResult> results)
        {
            var value1 = ObjectReader.GetProperty(value, _property1);
            var value2 = ObjectReader.GetProperty(value, _property2);

            if (!ObjectComparator.Compare(value1, _operation, value2))
            {
                results.Add(
                    new ValidationResult(
                        path,
                        ValidationResultType.Error,
                        "PROPERTIES_NOT_MATCH",
                        "Property " + _property1 + " is expected to " + _operation + " property " + _property2,
                        value2,
                        value1
                        )
                    );
            }
        }
        public void Validate(string path, Schema schema, object value, List <ValidationResult> results)
        {
            var found = new List <string>();

            foreach (var property in _properties)
            {
                var propertyValue = ObjectReader.GetProperty(value, property);
                if (propertyValue != null)
                {
                    found.Add(property);
                }
            }

            if (found.Count == 0)
            {
                results.Add(
                    new ValidationResult(
                        path,
                        ValidationResultType.Error,
                        "VALUE_NULL",
                        "At least one property expected from " + _properties,
                        _properties,
                        null
                        )
                    );
            }
            else if (found.Count > 1)
            {
                results.Add(
                    new ValidationResult(
                        path,
                        ValidationResultType.Error,
                        "VALUE_ONLY_ONE",
                        "Only one property expected from " + _properties,
                        _properties,
                        found.ToArray()
                        )
                    );
            }
        }