コード例 #1
0
        public void ReaderPerformance()
        {
            ReaderValidation();

            using (var tester = new PerformanceTester("Reader"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    ReaderValidation();
                }
            }
        }
コード例 #2
0
        public void ReaderPerformance()
        {
            ReaderValidation();

            using (var tester = new PerformanceTester("Reader"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    ReaderValidation();
                }
            }
        }
コード例 #3
0
        public void IsValidPerformance_Failure()
        {
            JArray a = JArray.Parse(JsonFailure);
            a.IsValid(Schema);

            using (var tester = new PerformanceTester("IsValid_Failure"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    a.IsValid(Schema);
                }
            }
        }
コード例 #4
0
        public void IsValidPerformance_Failure()
        {
            JArray a = JArray.Parse(JsonFailure);

            a.IsValid(Schema);

            using (var tester = new PerformanceTester("IsValid_Failure"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    a.IsValid(Schema);
                }
            }
        }
コード例 #5
0
        public void IsValid_SchemaSpec()
        {
            string schemaJson = TestHelpers.OpenFileText(@"resources\schemas\schema-draft-v4.json");
            JSchema s = JSchema.Parse(schemaJson);
            JObject o = JObject.Parse(schemaJson);
            o.IsValid(s);

            using (var tester = new PerformanceTester("IsValid_SchemaSpec"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    o.IsValid(s);
                }
            }
        }
コード例 #6
0
        public void IsValid_SchemaSpec()
        {
            string  schemaJson = TestHelpers.OpenFileText(@"resources\schemas\schema-draft-v4.json");
            JSchema s          = JSchema.Parse(schemaJson);
            JObject o          = JObject.Parse(schemaJson);

            o.IsValid(s);

            using (var tester = new PerformanceTester("IsValid_SchemaSpec"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    o.IsValid(s);
                }
            }
        }
コード例 #7
0
        public void DeeplyNestedConditionalScopes()
        {
            string schemaJson = TestHelpers.OpenFileText(@"resources\schemas\components-10definitions.schema.json");

            string json = TestHelpers.OpenFileText(@"resources\json\components-5levels.json");

            JSchema schema = JSchema.Parse(schemaJson);

            ReaderValidation(json, schema);

            using (var tester = new PerformanceTester("DeeplyNestedConditionalScopes"))
            {
                for (int i = 1; i < ValidationCount; i++)
                {
                    ReaderValidation();
                }
            }
        }
コード例 #8
0
        public void ReaderPerformance()
        {
            string json = @"[
    {
        ""id"": 2,
        ""name"": ""An ice sculpture"",
        ""price"": 12.50,
        ""tags"": [""cold"", ""ice""],
        ""dimensions"": {
            ""length"": 7.0,
            ""width"": 12.0,
            ""height"": 9.5
        },
        ""warehouseLocation"": {
            ""latitude"": -78.75,
            ""longitude"": 20.4
        }
    },
    {
        ""id"": 3,
        ""name"": ""A blue mouse"",
        ""price"": 25.50,
        ""dimensions"": {
            ""length"": 3.1,
            ""width"": 1.0,
            ""height"": 1.0
        },
        ""warehouseLocation"": {
            ""latitude"": 54.4,
            ""longitude"": -32.7
        }
    }
]";

            JSchema schema = JSchema.Parse(@"{
    ""$schema"": ""http://json-schema.org/draft-04/schema#"",
    ""title"": ""Product set"",
    ""type"": ""array"",
    ""items"": {
        ""title"": ""Product"",
        ""type"": ""object"",
        ""properties"": {
            ""id"": {
                ""description"": ""The unique identifier for a product"",
                ""type"": ""number""
            },
            ""name"": {
                ""type"": ""string""
            },
            ""price"": {
                ""type"": ""number"",
                ""minimum"": 0,
                ""exclusiveMinimum"": true
            },
            ""tags"": {
                ""type"": ""array"",
                ""items"": {
                    ""type"": ""string""
                },
                ""minItems"": 1,
                ""uniqueItems"": true
            },
            ""dimensions"": {
                ""type"": ""object"",
                ""properties"": {
                    ""length"": {""type"": ""number""},
                    ""width"": {""type"": ""number""},
                    ""height"": {""type"": ""number""}
                },
                ""required"": [""length"", ""width"", ""height""]
            },
            ""warehouseLocation"": {
                ""description"": ""A geographical coordinate"",
                ""type"": ""object"",
                ""properties"": {
                    ""latitude"": { ""type"": ""number"" },
                    ""longitude"": { ""type"": ""number"" }
                }
            }
        },
        ""required"": [""id"", ""name"", ""price""]
    }
}");

            using (var tester = new PerformanceTester("Reader"))
            {
                for (int i = 0; i < 1000; i++)
                {
                    JsonTextReader          reader           = new JsonTextReader(new StringReader(json));
                    JSchemaValidatingReader validatingReader = new JSchemaValidatingReader(reader);
                    validatingReader.Schema = schema;

                    while (validatingReader.Read())
                    {
                    }
                }
            }
        }
コード例 #9
0
        public void ReaderPerformance()
        {
            string json = @"[
    {
        ""id"": 2,
        ""name"": ""An ice sculpture"",
        ""price"": 12.50,
        ""tags"": [""cold"", ""ice""],
        ""dimensions"": {
            ""length"": 7.0,
            ""width"": 12.0,
            ""height"": 9.5
        },
        ""warehouseLocation"": {
            ""latitude"": -78.75,
            ""longitude"": 20.4
        }
    },
    {
        ""id"": 3,
        ""name"": ""A blue mouse"",
        ""price"": 25.50,
        ""dimensions"": {
            ""length"": 3.1,
            ""width"": 1.0,
            ""height"": 1.0
        },
        ""warehouseLocation"": {
            ""latitude"": 54.4,
            ""longitude"": -32.7
        }
    }
]";

            JSchema schema = JSchema.Parse(@"{
    ""$schema"": ""http://json-schema.org/draft-04/schema#"",
    ""title"": ""Product set"",
    ""type"": ""array"",
    ""items"": {
        ""title"": ""Product"",
        ""type"": ""object"",
        ""properties"": {
            ""id"": {
                ""description"": ""The unique identifier for a product"",
                ""type"": ""number""
            },
            ""name"": {
                ""type"": ""string""
            },
            ""price"": {
                ""type"": ""number"",
                ""minimum"": 0,
                ""exclusiveMinimum"": true
            },
            ""tags"": {
                ""type"": ""array"",
                ""items"": {
                    ""type"": ""string""
                },
                ""minItems"": 1,
                ""uniqueItems"": true
            },
            ""dimensions"": {
                ""type"": ""object"",
                ""properties"": {
                    ""length"": {""type"": ""number""},
                    ""width"": {""type"": ""number""},
                    ""height"": {""type"": ""number""}
                },
                ""required"": [""length"", ""width"", ""height""]
            },
            ""warehouseLocation"": {
                ""description"": ""A geographical coordinate"",
                ""type"": ""object"",
                ""properties"": {
                    ""latitude"": { ""type"": ""number"" },
                    ""longitude"": { ""type"": ""number"" }
                }
            }
        },
        ""required"": [""id"", ""name"", ""price""]
    }
}");

            using (var tester = new PerformanceTester("Reader"))
            {
                for (int i = 0; i < 1000; i++)
                {
                    JsonTextReader reader = new JsonTextReader(new StringReader(json));
                    JSchemaValidatingReader validatingReader = new JSchemaValidatingReader(reader);
                    validatingReader.Schema = schema;

                    while (validatingReader.Read())
                    {
                    }
                }
            }
        }