public void CanLoadDefinitionsFromCommon() { JSchemaManagementRegistry registry = new JSchemaManagementRegistry(RootData); JSchemaClassManager classManager = registry.Get <JSchemaClassManager>(); JSchemaClass common = classManager.LoadJSchemaClassFile(new HomePath("~/.data/JsonSchema/common_v1.yaml")); OutLine(common.ToJson(true)); IEnumerable <JSchemaClass> definitions = JSchemaClass.FromDefinitions(common.JSchema, classManager); OutLine(definitions.ToJson(true), ConsoleColor.Yellow); }
public void CanGetRootClassName() { // check @type // check title // check javaType // check _tableNameProperties JSchema jSchema = JSchemaLoader.LoadYamlJSchema(OrganizationDataPath); JSchemaClassManager classManager = new JSchemaClassManager("@type", "title", "javaType"); JSchemaClass orgClass = classManager.LoadJSchemaClassFile(OrganizationDataPath); string className = orgClass.ClassName; Expect.IsNotNullOrEmpty(className); Expect.AreEqual("Organization", className); }
public void CanGetPropertyNames() { JSchema jSchema = JSchemaLoader.LoadYamlJSchema(OrganizationDataPath); JSchemaClassManager jSchemaClassManager = new JSchemaClassManager("@type", "title", "javaType"); JSchemaClass jSchemaClass = jSchemaClassManager.LoadJSchemaClassFile(OrganizationDataPath); string[] propertyNames = jSchemaClass.Properties.Select(p => p.PropertyName).ToArray(); HashSet <string> propertyNameHashSet = new HashSet <string>(propertyNames); propertyNameHashSet.Contains("FriendlyId").IsTrue("FriendlyId not found"); propertyNameHashSet.Contains("WebsiteUrl").IsTrue("WebsiteUrl not found"); propertyNameHashSet.Contains("BusinessName").IsTrue("BusinessName not found"); propertyNameHashSet.Contains("TaxIds").IsTrue("TaxIds"); propertyNameHashSet.Contains("IndustryCodes").IsTrue("IndustryCodes"); }
public void CanLoadJSchemaClassWithClassName2() { JSchemaManagementRegistry registry = JSchemaManagementRegistry.CreateForYaml(RootData, "@type", "javaType", "class", "className"); JSchemaClassManager classManager = registry.Get <JSchemaClassManager>(); classManager.SetClassNameMunger("javaType", javaType => { string[] split = javaType.DelimitSplit("."); return(split[split.Length - 1]); }); JSchemaClass census = classManager.LoadJSchemaClassFile(new HomePath("~/.data/JsonSchema/census_v1.yaml")); Expect.IsNotNull(census); Expect.AreEqual("Census", census.ClassName); Expect.AreEqual(4, census.Properties.Count()); Message.PrintLine("Properties: {0}", census.Properties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Value properties: {0}", census.ValueProperties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Array properties: {0}", census.ArrayProperties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Object properties: {0}", census.ObjectProperties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Enum properties: \r\n\t{0}", ConsoleColor.Blue, census.EnumProperties.ToArray().ToDelimited(p => p.PropertyName + ": " + p.GetEnumNames().ToArray().ToDelimited(en => en, "|"), "\r\n")); }
public void CanLoadJSchemaClassWithClassName() { JSchemaManagementRegistry registry = JSchemaManagementRegistry.CreateForYaml(RootData, "@type", "class", "className"); JSchemaClassManager classManager = registry.Get <JSchemaClassManager>(); JSchemaClass app = classManager.LoadJSchemaClassFile(new HomePath("~/.data/JsonSchema/application_v1.yaml")); Expect.IsNotNull(app); Expect.AreEqual("Application", app.ClassName); Expect.AreEqual(22, app.Properties.Count()); Message.PrintLine("Properties: {0}", app.Properties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Value properties: {0}", app.ValueProperties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Array properties: {0}", app.ArrayProperties.ToArray().ToDelimited(p => p.PropertyName + $"[{p.ClassOfArrayItems.ClassName}]")); Message.PrintLine("Object properties: {0}", app.ObjectProperties.ToArray().ToDelimited(p => p.PropertyName)); Message.PrintLine("Enum properties: \r\n\t{0}", ConsoleColor.Blue, app.EnumProperties.ToArray().ToDelimited(p => p.PropertyName + ": " + p.GetEnumNames().ToArray().ToDelimited(en => en, "|"), "\r\n")); JSchemaProperty proposalDetail = app["ProposalDetail"]; Expect.IsNotNull(proposalDetail); Message.PrintLine(proposalDetail.ToJson(true), ConsoleColor.Yellow); Message.PrintLine(proposalDetail.JSchemaOfProperty.ToJson(true), ConsoleColor.DarkYellow); }