Beispiel #1
0
        public void OneOf_NoneValid()
        {
            JSchema schema = JSchema.Parse(@"{
                ""type"": ""string"",
                ""oneOf"" : [
                    {
                        ""type"": ""object""
                    },
                    {
                        ""maxLength"": 4
                    }
                ]
            }");

            JToken json = JToken.Parse(@"""foo foo""");

            IList <ValidationError> errors;

            Assert.IsFalse(json.IsValid(schema, out errors));
            Assert.AreEqual(1, errors.Count);

            ValidationError error = errors.Single();

            StringAssert.AreEqual("JSON is valid against more than one schema from 'oneOf'. No valid schemas. Path '', line 1, position 9.", error.BuildExtendedMessage());
            Assert.AreEqual(2, error.ChildErrors.Count);
            StringAssert.AreEqual(@"String 'foo foo' exceeds maximum length of 4. Path '', line 1, position 9.", error.ChildErrors[0].BuildExtendedMessage());
            StringAssert.AreEqual(@"Invalid type. Expected Object but got String. Path '', line 1, position 9.", error.ChildErrors[1].BuildExtendedMessage());
        }