Exemplo n.º 1
0
        public void LoadRemoteSchemas()
        {
            var remotesPath = Path.Combine(TestContext.CurrentContext.WorkDirectory, _remoteSchemasPath)
                              .AdjustForPlatform();

            if (!Directory.Exists(remotesPath))
            {
                throw new Exception("Cannot find remotes folder");
            }

            var fileNames = Directory.GetFiles(remotesPath, "*.json", SearchOption.AllDirectories);

            foreach (var fileName in fileNames)
            {
                var schema = JsonSchema.FromFile(fileName);
                var uri    = new Uri(fileName.Replace(remotesPath, "http://localhost:1234").Replace('\\', '/'));
                SchemaRegistry.Global.Register(uri, schema);
            }
        }
Exemplo n.º 2
0
        public void Issue29_SchemaFromFileWithIdShouldKeepUriFromId()
        {
            var schemaFile = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Files", "issue29-schema-with-id.json")
                             .AdjustForPlatform();

            var jsonStr    = @"{
  ""abc"": {
    ""abc"": {
        ""abc"": ""abc""
    }
  }
}";
            var schema     = JsonSchema.FromFile(schemaFile);
            var json       = JsonDocument.Parse(jsonStr).RootElement;
            var validation = schema.Validate(json, new ValidationOptions {
                OutputFormat = OutputFormat.Detailed
            });

            validation.AssertValid();
        }