Exemple #1
0
        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);
        }
Exemple #2
0
        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"));
        }