Exemplo n.º 1
0
        public void SimpleTypeValidationValid()
        {
            var schema = SchemaBuilderTests.SimpleSchemaExample();

            var newObj = new
            {
                stringProp = "seattle, wa",
                urlProp    = "http://example.org",
                numberProp = 1234567901,
                dateProp   = DateTime.UtcNow,
                floatProp  = 123123.1231231231
            };

            string json = JsonConvert.SerializeObject(newObj, Settings);

            var issues = new IssueLogger();

            Assert.IsTrue(schema.ValidateJson(new JsonExample(json), issues, null, null));
            Assert.AreEqual(0, issues.Issues.Count());
        }
Exemplo n.º 2
0
        public void SimpleTypeValidationMissingProperty()
        {
            var schema = SchemaBuilderTests.SimpleSchemaExample();

            var newObj = new
            {
                stringProp = "seattle, wa",
                numberProp = 1234567901,
                dateProp   = DateTime.UtcNow,
                floatProp  = 123123.1231231231
            };

            string json = JsonConvert.SerializeObject(newObj, Settings);

            var issues = new IssueLogger();

            Assert.IsFalse(schema.ValidateJson(new JsonExample(json), issues, null, null));
            Assert.AreEqual(1, issues.Issues.Count());
            Assert.AreEqual(ValidationErrorCode.RequiredPropertiesMissing, issues.Issues.First().Code);
        }
Exemplo n.º 3
0
        public void SimpleTypeValidationWrongTypeArray()
        {
            var schema = SchemaBuilderTests.SimpleSchemaExample();

            var newObj = new
            {
                stringProp = new string[] { "one", "two", "three" },
                urlProp    = "http://example.org",
                numberProp = 1234567901,
                dateProp   = DateTime.UtcNow,
                floatProp  = 123123.1231231231
            };

            string json = JsonConvert.SerializeObject(newObj, Settings);

            var issues = new IssueLogger();

            Assert.IsFalse(schema.ValidateJson(new JsonExample(json), issues, null, null));
            Assert.AreEqual(1, issues.Issues.Count());
            Assert.AreEqual(ValidationErrorCode.ExpectedNonArrayValue, issues.Issues.First().Code);
        }
Exemplo n.º 4
0
        public void SimpleTypeValidationExtraProperty()
        {
            var schema = SchemaBuilderTests.SimpleSchemaExample();

            var newObj = new
            {
                stringProp = "seattle, wa",
                foobar     = "another value",
                urlProp    = "http://example.org",
                numberProp = 1234567901,
                dateProp   = DateTime.UtcNow,
                floatProp  = 123123.1231231231
            };

            string json = JsonConvert.SerializeObject(newObj, Settings);

            var issues = new IssueLogger();

            Assert.IsFalse(schema.ValidateJson(new JsonExample(json), issues, null, null));
            Assert.AreEqual(1, issues.Issues.Count());
            Assert.AreEqual(ValidationErrorCode.AdditionalPropertyDetected, issues.Issues.First().Code);
        }
Exemplo n.º 5
0
        public void SimpleTypeValidationWrongPropertyType()
        {
            var schema = SchemaBuilderTests.SimpleSchemaExample();

            // There are two errors here, the first is that stringProp is a number, and the
            // the second is that numberProp is a string. API Doctor needs to catch both.
            var newObj = new
            {
                stringProp = 1231234,
                urlProp    = "http://example.org",
                numberProp = "1234567901",
                dateProp   = DateTime.UtcNow,
                floatProp  = 123123.1231231231
            };

            string json = JsonConvert.SerializeObject(newObj, Settings);

            var issues = new IssueLogger();

            Assert.IsFalse(schema.ValidateJson(new JsonExample(json), issues, null, null));
            Assert.IsTrue(issues.Issues.All(error => error.Code == ValidationErrorCode.ExpectedTypeDifferent));
            Assert.AreEqual(2, issues.Issues.Count(), "Expected 2 errors in the response");
        }