public void EnsureCreateClass_FromSqlTableReference_AndFromQuery_ProduceEquivalentResults() { string classFromQuery = string.Empty, classFromTable = string.Empty; "Given a C# class generated from a query" ._(() => { var query = string.Format("select * from {0}", TableName); classFromQuery = CSharpClassGeneratorFromQueryViaSqlDescribeResultSet .GenerateClass(SqlConnectionProviders.AdventureWorksDb, query, "Employee"); var compileResults = RoslynHelper.TryCompile(classFromQuery); compileResults.IsValid().Should().BeTrue(); }); "Given a C# class generated from SQL InformationSchema metadata" ._(() => { var sqlTableReference = new SqlTableReference(SqlConnectionProviders.AdventureWorksDb, TableName); classFromTable = CSharpClassGeneratorFromInformationSchema.CreateCSharpClass(sqlTableReference); var compileResults = RoslynHelper.TryCompile(classFromTable); compileResults.IsValid().Should().BeTrue(); }); "They should produce identical output" ._(() => { Console.WriteLine("From Query:\r\n" + classFromQuery); Console.WriteLine("From Table:\r\n" + classFromTable); classFromTable.Should().BeEquivalentTo(classFromQuery); }); }
private static string GetCSharpClassFromAdoSchemaTableColumns(IList <CSharpProperty> cSharpProperties) { var cSharpClass = CSharpClassTextGenerator.GenerateClassText("SysTypes", cSharpProperties, CSharpClassTextGeneratorOptions.Default); var compileResult = RoslynHelper.TryCompile(cSharpClass); compileResult.IsValid().Should().BeTrue(); return(cSharpClass); }
public void CreateClassFromSqlTableReference() { var sqlTableReference = new SqlTableReference(SqlConnectionProviders.AdventureWorksDb, TableName); var cSharpClass = CSharpClassGeneratorFromInformationSchema.CreateCSharpClass(sqlTableReference); var compileResult = RoslynHelper.TryCompile(cSharpClass); compileResult.IsValid().Should().BeTrue(); Console.WriteLine(cSharpClass); }
public void CreateClassForDocumentTableFromQueryTest() { var cSharpClass = CSharpClassGeneratorFromQueryViaSqlDescribeResultSet.GenerateClass( SqlConnectionProviders.AdventureWorksDb, $"SELECT * from Production.Document", "Document"); var compileResult = RoslynHelper.TryCompile(cSharpClass); compileResult.IsValid().Should().BeTrue(); Console.WriteLine(cSharpClass); }
public void CreateClassFromQueryTest() { var cSharpClass = CSharpClassGeneratorFromQueryViaSqlDescribeResultSet.GenerateClass( SqlConnectionProviders.AdventureWorksDb, $"SELECT * from {TableName}", "Employee"); var compileResult = RoslynHelper.TryCompile(cSharpClass); compileResult.IsValid().Should().BeTrue(); Console.WriteLine(cSharpClass); cSharpClass.Should().Be(EmployeeCSharpClassText); }
public void TestCompilationOfManyClasses() { int errorCount = 0; int successCount = 0; IList <SqlTableReference> randomSqlTableReferences = null; "Given a list of SqlTableReferences" ._(() => { randomSqlTableReferences = RandomTableSelector.GetRandomSqlTableReferences(SqlConnectionProviders.AdventureWorksDb, 400); }); "Convert each table reference to a C# class and check for syntax errors using Roslyn" ._foreach(randomSqlTableReferences, sqlTableReference => { var sqlTable = SqlTableFactory.Create(sqlTableReference); var cSharpClass = CSharpClassGeneratorFromSqlTable.GenerateClass(sqlTable); var compileResult = RoslynHelper.TryCompile(cSharpClass); if (compileResult.IsValid()) { successCount++; } else { errorCount++; Console.WriteLine("Error found in the following:\r\n" + cSharpClass); } }); "Then print out testing results" ._(() => { Console.WriteLine("Successes: {0}", successCount); Console.WriteLine("Failures: {0}", errorCount); errorCount.Should().Be(0); }); }