コード例 #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);
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        public void CanGetClassManagerWithNameParser()
        {
            JSchemaManagementRegistry registry     = new JSchemaManagementRegistry(RootData);
            JSchemaClassManager       classManager = registry.Get <JSchemaClassManager>();

            Expect.IsNotNull(classManager.JSchemaNameParser);
        }
コード例 #4
0
        public void CanGenerateSchemaDefinition()
        {
            JSchemaManagementRegistry        registry  = JSchemaManagementRegistry.CreateForYaml(RootData);
            JSchemaSchemaDefinitionGenerator generator = registry.Get <JSchemaSchemaDefinitionGenerator>();
            JSchemaSchemaDefinition          jSchemaSchemaDefinition = generator.GenerateSchemaDefinition();

            Expect.IsNotNull(jSchemaSchemaDefinition, "jSchemaSchemaDefinition was null");
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
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"));
        }
コード例 #10
0
        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);
        }