public void CanLoadAllJSchemaClasses() { JSchemaManagementRegistry registry = JSchemaManagementRegistry.CreateForYaml(RootData, "@type", "javaType", "class", "className"); JSchemaClassManager classManager = registry.Get <JSchemaClassManager>(); classManager.SetClassNameMunger("javaType", javaType => { string[] split = javaType.DelimitSplit("."); string typeName = split[split.Length - 1]; if (typeName.EndsWith("Entity")) { typeName = typeName.Truncate("Entity".Length); } return(typeName); }); HashSet <JSchemaClass> results = classManager.GetAllJSchemaClasses(RootData); Expect.AreEqual(35, results.Count); Console.WriteLine($"Result count = {results.Count}"); StringBuilder output = new StringBuilder(); foreach (JSchemaClass jSchemaClass in results) { output.AppendFormat("ClassName={0}\r\n", jSchemaClass.ClassName); output.AppendLine(jSchemaClass.ToJson(true)); output.AppendLine("****"); } FileInfo outputFile = new FileInfo(new HomePath("~/.bam/data/testoutput.txt")); output.ToString().SafeWriteToFile(outputFile.FullName, true); Console.WriteLine("Wrote file {0}", outputFile.FullName); }
public void CanGenerateDaoSource() { Workspace workspace = Workspace.ForProcess(); string testSrcPath = workspace.Path("src", nameof(CanGenerateDaoSource)); if (Directory.Exists(testSrcPath)) { Directory.Delete(testSrcPath, true); } DirectoryInfo testSrcDir = new DirectoryInfo(testSrcPath); if (!testSrcDir.Exists) { testSrcDir.Create(); } JSchemaManagementRegistry registry = JSchemaManagementRegistry.CreateForYaml(RootData); JSchemaDaoAssemblyGenerator jSchemaDaoAssemblyGenerator = registry.Get <JSchemaDaoAssemblyGenerator>(); jSchemaDaoAssemblyGenerator.Namespace = "Bam.Net.JSchema.Generated.Classes"; FileInfo[] files = testSrcDir.GetFiles(); (files.Length == 0).IsTrue("There were files already in the target directory"); jSchemaDaoAssemblyGenerator.GenerateSource(testSrcPath); files = testSrcDir.GetFiles(); (files.Length > 0).IsTrue("No files were in the target directory"); }
public void CanGetClassManagerWithNameParser() { JSchemaManagementRegistry registry = new JSchemaManagementRegistry(RootData); JSchemaClassManager classManager = registry.Get <JSchemaClassManager>(); Expect.IsNotNull(classManager.JSchemaNameParser); }
public void CanGenerateSchemaDefinition() { JSchemaManagementRegistry registry = JSchemaManagementRegistry.CreateForYaml(RootData); JSchemaSchemaDefinitionGenerator generator = registry.Get <JSchemaSchemaDefinitionGenerator>(); JSchemaSchemaDefinition jSchemaSchemaDefinition = generator.GenerateSchemaDefinition(); Expect.IsNotNull(jSchemaSchemaDefinition, "jSchemaSchemaDefinition was null"); }
public void CanGetClassManagerFromRegistry() { JSchemaManagementRegistry registry = new JSchemaManagementRegistry(RootData); JSchemaClassManager classManager = registry.Get <JSchemaClassManager>(); Expect.IsNotNull(classManager.JSchemaResolver); (classManager.JSchemaResolver is FileSystemJSchemaResolver).IsTrue("unexpected resolver type"); Expect.IsNotNull(classManager.JSchemaNameParser); }
public void CanGetGenerator() { JSchemaManagementRegistry registry = JSchemaManagementRegistry.CreateForYaml(RootData); JSchemaSchemaDefinitionGenerator generator = registry.Get <JSchemaSchemaDefinitionGenerator>(); Expect.IsNotNull(generator, "generator was null"); Expect.IsNotNull(generator.SchemaManager, "SchemaManager was null"); Expect.IsNotNull(generator.JSchemaClassManager, "JSchemaSchemaClassManager was null"); Expect.IsNotNull(generator.Logger, "Logger was null"); }
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 CanLoadAllJSchemaClassesWithJavaJSchemaClassManager() { JSchemaManagementRegistry registry = JSchemaManagementRegistry.Create(RootData, SerializationFormat.Yaml, "@type", "javaType", "class", "className"); JSchemaClassManager classManager = registry.Get <JavaJSchemaClassManager>(); HashSet <JSchemaClass> results = classManager.GetAllJSchemaClasses(RootData); Expect.AreEqual(35, results.Count); Console.WriteLine($"Result count = {results.Count}"); StringBuilder output = new StringBuilder(); foreach (JSchemaClass jSchemaClass in results) { output.AppendFormat("ClassName={0}\r\n", jSchemaClass.ClassName); output.AppendLine(jSchemaClass.ToJson(true)); output.AppendLine("****"); } FileInfo outputFile = new FileInfo(new HomePath("~/.bam/data/javaTestOutput.txt")); output.ToString().SafeWriteToFile(outputFile.FullName, true); Console.WriteLine("Wrote file {0}", outputFile.FullName); }
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); }