public async Task BuildClassesForEntirePbsiDatabase() { /* * Two properties to tweak: * - Do we include the ValidFrom/ValidTo temporal columns * - Do we include the StringLength, Range, etc. attributes */ var includeTemporalColumns = true; var includeAttributes = false; var scp = new StaticSqlConnectionProvider("WS2016Sql", "PbsiS2STargetTemporal2"); await GeneratePbsiDatabaseTypes(scp, includeAttributes, includeTemporalColumns); }
public void WithIntegratedSecurityTest(StaticSqlConnectionProvider staticSqlConnectionProvider) { "Given a static sql connection provider with integrated security" ._(() => staticSqlConnectionProvider = new StaticSqlConnectionProvider(serverName, database)); "Then the connection string should not contain the username and password" ._(() => { var connectionString = staticSqlConnectionProvider.GetSqlConnectionString(); Console.WriteLine(connectionString); connectionString.Contains(serverName).Should().BeTrue(); connectionString.Contains(database).Should().BeTrue(); connectionString.Contains(username).Should().BeFalse(); connectionString.Contains(password).Should().BeFalse(); }); }
private static async Task GeneratePbsiDatabaseTypes(StaticSqlConnectionProvider scp, bool includeAttributes, bool includeTemporalColumns) { var generatorOptions = new CSharpClassTextGeneratorOptions() { IncludePropertyAnnotationAttributes = includeAttributes }; var tableDefinitions = await InformationSchemaMetadataExplorer.GetInformationSchemaTableDefinitions(scp); foreach (var tableDefinition in tableDefinitions) { if (string.Equals(tableDefinition.InformationSchemaTable.TABLE_SCHEMA, "PbsiSf", StringComparison.CurrentCultureIgnoreCase)) { continue; } var columns = tableDefinition.InformationSchemaColumns; if (!includeTemporalColumns) { columns = columns.Where(z => !z.COLUMN_NAME.InsensitiveEquals("validto") && !z.COLUMN_NAME.InsensitiveEquals("validfrom") ) .ToList(); } var tableName = tableDefinition.InformationSchemaTable.TABLE_NAME .Replace(".", "") .Replace("$", "_"); if (tableName.EndsWith("_History", StringComparison.OrdinalIgnoreCase)) { continue; } var cSharpClass = CSharpClassGeneratorFromInformationSchema.CreateCSharpClass( columns, tableName, generatorOptions ); Console.WriteLine(cSharpClass); } }
public void CreateSqlTableReferenceFromInformationSchemaTable_ShouldWork() { SISTable sisTable = null; var sqlConnectionProvider = new StaticSqlConnectionProvider("", ""); "Given a InformationSchemaTable" ._(() => { sisTable = InformationSchemaTableDefinitionFromJson.SampleTable().InformationSchemaTable; }); "Then we should be able to create a SqlTableReference from it" ._(() => { var sqlTableReference = sisTable.ToSqlTableReference(sqlConnectionProvider); sqlTableReference.SchemaName.Should().Be("HumanResources"); sqlTableReference.TableName.Should().Be("Employee"); sqlTableReference.SqlConnectionProvider.GetSqlConnectionString() .Should() .Be(sqlConnectionProvider.GetSqlConnectionString()); }); }