Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private JSchema GetJSchema(string dataPath, out JSchemaClassManager jSchemaClassManager)
        {
            JSchema jSchema = JSchemaLoader.LoadYamlJSchema(dataPath);

            jSchemaClassManager = GetJSchemaManager();
            return(jSchema);
        }
Ejemplo n.º 3
0
        public void CanGetClassManagerWithNameParser()
        {
            JSchemaManagementRegistry registry     = new JSchemaManagementRegistry(RootData);
            JSchemaClassManager       classManager = registry.Get <JSchemaClassManager>();

            Expect.IsNotNull(classManager.JSchemaNameParser);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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"));
        }
Ejemplo 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);
        }
Ejemplo n.º 11
0
 private JSchema GetOrganizationJSchema(out JSchemaClassManager jSchemaClassManager)
 {
     return(GetJSchema(OrganizationDataPath, out jSchemaClassManager));
 }
Ejemplo n.º 12
0
 private JSchema GetCompanyJSchema(out JSchemaClassManager jSchemaClassManager)
 {
     return(GetJSchema(CompanyDataPath, out jSchemaClassManager));
 }