Beispiel #1
0
        public void DictionaryHint(TestCase testCase)
        {
            Settings.GenerateEqualityComparers = true;
            Settings.HintDictionary            = new HintDictionary(testCase.HintsText);
            var generator = new DataModelGenerator(Settings, TestFileSystem.FileSystem);

            JsonSchema schema = SchemaReader.ReadSchema(testCase.SchemaText, TestUtil.TestFilePath);

            generator.Generate(schema);

            var expectedContentsDictionary = new Dictionary <string, ExpectedContents>
            {
                [Settings.RootClassName] = new ExpectedContents
                {
                    ClassContents         = testCase.ExpectedClassText,
                    ComparerClassContents = testCase.ExpectedComparerText
                }
            };

            // We won't bother to compare the contents of the original class (which
            // has no interesting properties), but the assertion method below needs to
            // know how many classes were generated.
            if (testCase.DefinesAdditionalClass)
            {
                expectedContentsDictionary.Add("D", new ExpectedContents());
            }

            Assert.FileContentsMatchExpectedContents(TestFileSystem, expectedContentsDictionary);
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            if (args.Length < 4)
            {
                Console.WriteLine("Usage: BSOA.FromJSchema <JSchemaPath> <OutputBsoaSchemaPath> <RootTypeName> <OutputNamespace>");
                return(-2);
            }

            try
            {
                string jschemaPath     = args[0];
                string outputPath      = args[1];
                string rootTypeName    = args[2];
                string outputNamespace = args[3];

                Console.WriteLine($"Converting jschema\r\n  '{jschemaPath}' to \r\n  '{outputPath}'...");
                JsonSchema schema = null;

                using (StreamReader sr = File.OpenText(jschemaPath))
                {
                    schema = SchemaReader.ReadSchema(sr, jschemaPath);
                }

                schema = JsonSchema.Collapse(schema);

                Database db = new Database($"{rootTypeName}Database", outputNamespace, rootTypeName);

                Table root = new Table(rootTypeName);
                db.Tables.Add(root);
                AddColumns(root, schema);

                foreach (KeyValuePair <string, JsonSchema> type in schema.Definitions)
                {
                    string tableName = type.Key.ToPascalCase();
                    if (TypeRenames.TryGetValue(tableName, out string renamed))
                    {
                        tableName = renamed;
                    }

                    Table table = new Table(tableName);
                    AddColumns(table, type.Value);
                    db.Tables.Add(table);
                }

                AsJson.Save(outputPath, db, verbose: true);
                Console.WriteLine("Done.");
                Console.WriteLine();

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: {ex}");
                return(-1);
            }
        }
Beispiel #3
0
        public void CanReadSchema(string fileNameStem, JsonSchema expected)
        {
            JsonSchema actual;

            using (var reader = new StreamReader(TestUtil.GetTestDataStream(fileNameStem)))
            {
                actual = SchemaReader.ReadSchema(reader, TestUtil.GetTestDataFilePath(fileNameStem));
            }

            actual.Should().Be(expected);
        }
Beispiel #4
0
        private ExportResult Import(ISheet sheet, string dataFilePath)
        {
            Schema schema = SchemaReader.ReadSchema(sheet, setting.headModel);

            if (dataFormat != DataFormat.None)
            {
                ImportData(sheet, schema, dataFilePath);
            }

            return(ExportResult.Success);
        }
Beispiel #5
0
        public void ThrowsOnLogicallyInvalidSchema(LogicallyInvalidSchemaTestCase test)
        {
            Action action = () =>
            {
                using (var reader = new StringReader(test.SchemaText))
                {
                    SchemaReader.ReadSchema(reader, TestUtil.TestFilePath);
                }
            };

            action.Should().Throw <SchemaValidationException>()
            .Where(ex => LogicallyInvalidSchemaExceptionPredicate(ex, test));
        }
Beispiel #6
0
        public void DetectsInvalidSchema(string jsonText)
        {
            Action action = () =>
            {
                using (var reader = new StringReader(jsonText))
                {
                    SchemaReader.ReadSchema(reader, TestUtil.TestFilePath);
                }
            };

            action.Should().Throw <JsonSyntaxException>()
            .Where(ex => ex.JsonReaderException.LineNumber == 2 &&
                   ex.JsonReaderException.LinePosition == 9);
        }
Beispiel #7
0
        private ExportResult ExportSheet(ISheet sheet)
        {
            Schema schema = SchemaReader.ReadSchema(sheet, setting.headModel);

            schema.name = setting.FormatSheetName(sheet);

            if (codeFormat != CodeFomat.None)
            {
                GenerateCode(schema);
            }

            if (dataFormat != DataFormat.None)
            {
                ExportData(sheet, schema);
            }

            return(ExportResult.Success);
        }