public void TestGetSchemaSimplePresent() { var schema1 = new JsonSchema { Id = "1", Title = "Title For 1" }; var schema2 = new JsonSchema { Id = "2", Title = "Title For 2" }; var schema3 = new JsonSchema { Id = "3", Title = "Title For 3" }; var resolver = new FutureJsonSchemaResolver(); resolver.LoadedSchemas.Add(schema1); resolver.LoadedSchemas.Add(schema2); resolver.LoadedSchemas.Add(schema3); var resolvedSchema2 = resolver.GetSchema("2"); var resolvedSchema1 = resolver.GetSchema("1"); var resolvedSchema3 = resolver.GetSchema("3"); Assert.AreSame(schema1, resolvedSchema1); Assert.AreSame(schema2, resolvedSchema2); Assert.AreSame(schema3, resolvedSchema3); }
public void TestGetSchemaSimpleMissing() { var schema1 = new JsonSchema { Id = "1", Title = "Title For 1" }; var schema2 = new JsonSchema { Id = "2", Title = "Title For 2" }; var schema3 = new JsonSchema { Id = "3", Title = "Title For 3" }; var resolver = new FutureJsonSchemaResolver(); resolver.LoadedSchemas.Add(schema1); resolver.LoadedSchemas.Add(schema2); resolver.LoadedSchemas.Add(schema3); var resolvedSchema2 = resolver.GetSchema("2"); var resolvedSchema1 = resolver.GetSchema("1"); var resolvedSchema3 = resolver.GetSchema("3"); var resolvedSchema4 = resolver.GetSchema("4") as FutureJsonSchema; var resolvedSchema5 = resolver.GetSchema("5") as FutureJsonSchema; Assert.AreSame(schema1, resolvedSchema1); Assert.AreSame(schema2, resolvedSchema2); Assert.AreSame(schema3, resolvedSchema3); Assert.IsNotNull(resolvedSchema4); Assert.IsNotNull(resolvedSchema5); Assert.False(resolvedSchema4.Resolved); Assert.False(resolvedSchema5.Resolved); }
internal static IDictionary <string, ISchema> ParseSchemas(JsonDictionary js) { js.ThrowIfNull("values"); RemoveAnnotations(js, 0); var working = new Dictionary <string, ISchema>(); var resolver = new FutureJsonSchemaResolver(); foreach (KeyValuePair <string, object> kvp in js) { logger.Debug("Found schema {0}", kvp.Key); var serilizer = new JsonSerializer(); var textWriter = new StringWriter(); serilizer.Serialize(textWriter, kvp.Value); string result = textWriter.ToString(); ISchema schema = new SchemaImpl(kvp.Key, result, resolver); working.Add(schema.Name, schema); } resolver.ResolveAndVerify(); return(working.AsReadOnly()); }
public void ArgumentValidationTest() { FutureJsonSchemaResolver resolver = new FutureJsonSchemaResolver(); Assert.Throws(typeof(ArgumentNullException), () => new SchemaImpl(null, JsonSchemaElement, resolver)); Assert.Throws(typeof(ArgumentNullException), () => new SchemaImpl("Activitiylist", null, resolver)); Assert.Throws(typeof(ArgumentNullException), () => new SchemaImpl("Activitiylist", JsonSchemaElement, null)); }
public void TestAddResolveFuture() { var resolver = new FutureJsonSchemaResolver(); Assert.AreEqual(0, resolver.LoadedSchemas.Count); var futureSchema1 = new FutureJsonSchema("1"); var schema1 = new JsonSchema { Id = "1", Title = "Title For 1" }; var futureSchema2 = new FutureJsonSchema("2"); var schema2 = new JsonSchema { Id = "2", Title = "Title For 2" }; resolver.LoadedSchemas.Add(futureSchema1); resolver.LoadedSchemas.Add(futureSchema2); Assert.AreEqual(2, resolver.LoadedSchemas.Count); resolver.LoadedSchemas.Add(schema2); Assert.AreEqual(2, resolver.LoadedSchemas.Count); var resolvedFuture2 = resolver.GetSchema("2") as FutureJsonSchema; var resolvedFuture1 = resolver.GetSchema("1") as FutureJsonSchema; Assert.NotNull(resolvedFuture1); Assert.NotNull(resolvedFuture2); Assert.AreSame(resolvedFuture1, futureSchema1); Assert.AreSame(resolvedFuture2, futureSchema2); Assert.IsFalse(resolvedFuture1.Resolved); Assert.IsTrue(resolvedFuture2.Resolved); Assert.AreEqual("Title For 2", resolvedFuture2.Title); Assert.IsNull(resolvedFuture1.Title); resolver.LoadedSchemas.Add(schema1); Assert.AreEqual(2, resolver.LoadedSchemas.Count); resolvedFuture2 = resolver.GetSchema("2") as FutureJsonSchema; resolvedFuture1 = resolver.GetSchema("1") as FutureJsonSchema; Assert.NotNull(resolvedFuture1); Assert.NotNull(resolvedFuture2); Assert.AreSame(resolvedFuture1, futureSchema1); Assert.AreSame(resolvedFuture2, futureSchema2); Assert.IsTrue(resolvedFuture1.Resolved); Assert.IsTrue(resolvedFuture2.Resolved); Assert.AreEqual("Title For 2", resolvedFuture2.Title); Assert.AreEqual("Title For 1", resolvedFuture1.Title); }
public void SimpleCreateTest() { FutureJsonSchemaResolver resolver = new FutureJsonSchemaResolver(); SchemaImpl impl = new SchemaImpl("Activitiylist", JsonSchemaElement, resolver); Assert.AreEqual("Activitiylist", impl.Id); Assert.AreEqual("Activitiylist", impl.Name); Assert.IsNotNull(impl.SchemaDetails); Assert.AreEqual(JsonSchemaType.Object, impl.SchemaDetails.Type); Assert.AreEqual(6, impl.SchemaDetails.Properties.Count); Assert.IsNotNull(impl.SchemaDetails.Properties["id"]); Assert.IsNotNull(impl.SchemaDetails.Properties["title"]); Assert.IsNotNull(impl.SchemaDetails.Properties["items"]); Assert.IsNotNull(impl.SchemaDetails.Properties["updated"]); Assert.IsNotNull(impl.SchemaDetails.Properties["links"]); Assert.IsNotNull(impl.SchemaDetails.Properties["kind"]); }
public void TestAddDuplicateFail() { var resolver = new FutureJsonSchemaResolver(); Assert.AreEqual(0, resolver.LoadedSchemas.Count); var schema1 = new JsonSchema { Id = "1" }; var schema2 = new JsonSchema { Id = "1" }; resolver.LoadedSchemas.Add(schema1); Assert.AreEqual(1, resolver.LoadedSchemas.Count); Assert.Throws<InvalidOperationException>(() => resolver.LoadedSchemas.Add(schema1)); Assert.AreEqual(1, resolver.LoadedSchemas.Count); Assert.Throws<InvalidOperationException>(() => resolver.LoadedSchemas.Add(schema2)); Assert.AreEqual(1, resolver.LoadedSchemas.Count); }
/// <summary> /// Creates a new instance of this schema implementation /// </summary> /// <param name="name"></param> /// <param name="jsonSchemaDefinition"></param> /// <param name="resolver"></param> public SchemaImpl(string name, string jsonSchemaDefinition, FutureJsonSchemaResolver resolver) { name.ThrowIfNullOrEmpty("name"); jsonSchemaDefinition.ThrowIfNullOrEmpty("jsonSchemaDefinition"); resolver.ThrowIfNull("resolver"); this.name = name; logger.Debug("Parsing Schema " + this.name); try { schema = JsonSchema.Parse(jsonSchemaDefinition, resolver); } catch (Exception ex) { throw new ArgumentException( string.Format("Failed to parse schema [{0}] which was defined as [{1}]", name, jsonSchemaDefinition), ex); } }
public void TestAddDuplicateFail() { var resolver = new FutureJsonSchemaResolver(); Assert.AreEqual(0, resolver.LoadedSchemas.Count); var schema1 = new JsonSchema { Id = "1" }; var schema2 = new JsonSchema { Id = "1" }; resolver.LoadedSchemas.Add(schema1); Assert.AreEqual(1, resolver.LoadedSchemas.Count); Assert.Throws <InvalidOperationException>(() => resolver.LoadedSchemas.Add(schema1)); Assert.AreEqual(1, resolver.LoadedSchemas.Count); Assert.Throws <InvalidOperationException>(() => resolver.LoadedSchemas.Add(schema2)); Assert.AreEqual(1, resolver.LoadedSchemas.Count); }
public void TestValidate() { var schema1 = new JsonSchema { Id = "1", Title = "Title For 1" }; var schema2 = new JsonSchema { Id = "2", Title = "Title For 2" }; var schema3 = new JsonSchema { Id = "3", Title = "Title For 3" }; var schema4 = new JsonSchema { Id = "4", Title = "Title For 4" }; var schema5 = new JsonSchema { Id = "5", Title = "Title For 5" }; var resolver = new FutureJsonSchemaResolver(); resolver.LoadedSchemas.Add(schema1); resolver.LoadedSchemas.Add(schema2); resolver.LoadedSchemas.Add(schema3); resolver.GetSchema("4"); // Adds 4 resolver.GetSchema("5"); // Adds 5 Assert.Throws <InvalidOperationException>(resolver.ResolveAndVerify); resolver.LoadedSchemas.Add(schema5); Assert.Throws <InvalidOperationException>(resolver.ResolveAndVerify); resolver.LoadedSchemas.Add(schema4); Assert.DoesNotThrow(resolver.ResolveAndVerify); }
public void TestAddSimple() { var resolver = new FutureJsonSchemaResolver(); Assert.AreEqual(0, resolver.LoadedSchemas.Count); var schema1 = new JsonSchema { Id = "1" }; var schema2 = new JsonSchema { Id = "2" }; resolver.LoadedSchemas.Add(schema1); Assert.AreEqual(1, resolver.LoadedSchemas.Count); Assert.True(ReferenceEquals(schema1, resolver.LoadedSchemas[0])); resolver.LoadedSchemas.Add(schema2); Assert.AreEqual(2, resolver.LoadedSchemas.Count); Assert.True(ReferenceEquals(schema1, resolver.LoadedSchemas[0])); Assert.True(ReferenceEquals(schema2, resolver.LoadedSchemas[1])); }
public void TestValidate() { var schema1 = new JsonSchema { Id = "1", Title = "Title For 1" }; var schema2 = new JsonSchema { Id = "2", Title = "Title For 2" }; var schema3 = new JsonSchema { Id = "3", Title = "Title For 3" }; var schema4 = new JsonSchema { Id = "4", Title = "Title For 4" }; var schema5 = new JsonSchema { Id = "5", Title = "Title For 5" }; var resolver = new FutureJsonSchemaResolver(); resolver.LoadedSchemas.Add(schema1); resolver.LoadedSchemas.Add(schema2); resolver.LoadedSchemas.Add(schema3); resolver.GetSchema("4"); // Adds 4 resolver.GetSchema("5"); // Adds 5 Assert.Throws<InvalidOperationException>(resolver.ResolveAndVerify); resolver.LoadedSchemas.Add(schema5); Assert.Throws<InvalidOperationException>(resolver.ResolveAndVerify); resolver.LoadedSchemas.Add(schema4); Assert.DoesNotThrow(resolver.ResolveAndVerify); }