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); }
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); } }
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); }
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); }
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)); }
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); }
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); }