public void AddDetailsSubschemaTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var schema = new JsonSchema() { Id = "NamedSchema" }; var propertySchema = new JsonSchema(); var itemSchema = new JsonSchema(); var additionalPropertiesSchema = new JsonSchema(); schema.Items = new List <JsonSchema>(); schema.Properties = new Dictionary <string, JsonSchema>(); schema.AdditionalProperties = additionalPropertiesSchema; // Check properties and items. schema.Items.Add(itemSchema); schema.Properties.Add("TestProperty", propertySchema); ImplementationDetailsGenerator.AddDetails(dic, schema); // Confirm results. Assert.AreEqual(4, dic.Count); Assert.AreEqual("NamedSchema", dic[itemSchema].ProposedName); Assert.AreEqual("TestPropertyData", dic[propertySchema].ProposedName); Assert.AreEqual("NamedSchemaProperties", dic[additionalPropertiesSchema].ProposedName); }
public void AddIsMethodResultTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var schema = new JsonSchema(); var service = new MockService(); service.Schemas.Add("TestSchema", new MockSchema() { SchemaDetails = schema }); var method = new MockMethod() { ResponseType = "TestSchema" }; // Test parameter validation: Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.AddIsMethodResult(null, service, method)); Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.AddIsMethodResult(dic, null, method)); Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.AddIsMethodResult(dic, service, (IMethod)null)); // Test single add: ImplementationDetailsGenerator.AddIsMethodResult(dic, service, method); Assert.AreEqual(dic.Count, 1); var implDetails = dic[schema]; Assert.IsTrue(implDetails.IsMethodResult); }
public void ProposeNameIfNecessaryTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); // Test parameter validation. Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.ProposeNameIfNecessary(null, "a", new JsonSchema())); Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.ProposeNameIfNecessary(dic, null, new JsonSchema())); Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.ProposeNameIfNecessary(dic, "a", null)); // Test with already named schema. ImplementationDetailsGenerator.ProposeNameIfNecessary(dic, "Test", new JsonSchema() { Id = "Test" }); Assert.AreEqual(0, dic.Count); // Test with unnamed schema. var schema = new JsonSchema(); ImplementationDetailsGenerator.ProposeNameIfNecessary(dic, "Test", schema); Assert.AreEqual(1, dic.Count); Assert.AreEqual("Test", dic[schema].ProposedName); }
public GoogleSchemaGenerator(IEnumerable <ISchemaDecorator> decorators, string schemaNamespace) { decorators.ThrowIfNull("decorators"); schemaNamespace.ThrowIfNull("schemaNamespace"); this.decorators = new List <ISchemaDecorator>(decorators).AsReadOnly(); this.schemaNamespace = schemaNamespace; this.implementationDetailsGenerator = new ImplementationDetailsGenerator(); }
public void GenerateDetailsTest() { var gen = new ImplementationDetailsGenerator(); Assert.Throws <ArgumentNullException>(() => gen.GenerateDetails(null)); // Test the generation for the mock service. var service = new MockService(); IDictionary <JsonSchema, SchemaImplementationDetails> dic = gen.GenerateDetails(service); Assert.IsNotNull(dic); Assert.AreEqual(dic.Count, 0); }
public void AddDetailsRecursionTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var schema = new JsonSchema(); // Check endless recursion handling schema.Properties = new Dictionary <string, JsonSchema>(); schema.Properties.Add("Myself", schema); ImplementationDetailsGenerator.AddDetails(dic, schema); Assert.AreEqual(1, dic.Count); // Confirm name proposal Assert.AreEqual("MyselfData", dic[schema].ProposedName); }
public void AddDetailsTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var schema = new JsonSchema(); // Test parameter validation. Assert.Throws <ArgumentNullException>(() => ImplementationDetailsGenerator.AddDetails(null, schema)); Assert.Throws <ArgumentNullException>(() => ImplementationDetailsGenerator.AddDetails(dic, null)); // Test simple execution. ImplementationDetailsGenerator.AddDetails(dic, schema); Assert.AreEqual(1, dic.Count); Assert.IsTrue(dic[schema].TraversedByGenerator); }
public void AddIsMethodResultRecursionTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var schema = new JsonSchema(); var method = new MockMethod() { ResponseType = "TestSchema" }; var subresource = new MockResource(); subresource.Methods.Add("TestMethod", method); var resource = new MockResource(); resource.Resources.Add("Subresource", subresource); var service = new MockService(); service.Schemas.Add("TestSchema", new MockSchema { SchemaDetails = schema }); service.Resources.Add("TestResource", resource); // Test parameter validation: Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.AddIsMethodResult(null, service, service.Resources.Values)); Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.AddIsMethodResult(dic, null, service.Resources.Values)); Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.AddIsMethodResult(dic, service, (IEnumerable <IResource>)null)); // Test recursive add: ImplementationDetailsGenerator.AddIsMethodResult(dic, service, service.Resources.Values); Assert.AreEqual(dic.Count, 1); var implDetails = dic[schema]; Assert.IsTrue(implDetails.IsMethodResult); }
public void GetOrCreateDetailsTest() { var dic = new Dictionary <JsonSchema, SchemaImplementationDetails>(); var schema = new JsonSchema(); // Test parameter validation Assert.Throws <ArgumentNullException>( () => ImplementationDetailsGenerator.GetOrCreateDetails(null, schema)); Assert.Throws <ArgumentNullException>(() => ImplementationDetailsGenerator.GetOrCreateDetails(dic, null)); // Test single add SchemaImplementationDetails details; Assert.IsNotNull(details = ImplementationDetailsGenerator.GetOrCreateDetails(dic, schema)); // Test duplicate Assert.AreEqual(details, ImplementationDetailsGenerator.GetOrCreateDetails(dic, schema)); // Test second add var schema2 = new JsonSchema(); Assert.IsNotNull(ImplementationDetailsGenerator.GetOrCreateDetails(dic, schema2)); Assert.AreEqual(2, dic.Count); }