Exemple #1
0
    public void CreateClassFromSqlTableReferenceForActualUseWhenNeedingToGenerateCSharpClasses()
    {
        var sqlTableReference = new SqlTableReference(SqlConnectionProviders.PbsiCopy, "PbsiWM.MTDINV_LINE");
        var sqlTable          = SqlTableFactory.Create(sqlTableReference);
        var cSharpClass       = CSharpClassGeneratorFromSqlTable.GenerateClass(sqlTable);

        Console.WriteLine(cSharpClass);
    }
Exemple #2
0
    public void CreateClassFromSqlTableReference()
    {
        var sqlTableReference = new SqlTableReference(SqlConnectionProviders.AdventureWorksDb, TableName);
        var sqlTable          = SqlTableFactory.Create(sqlTableReference);
        var cSharpClass       = CSharpClassGeneratorFromSqlTable.GenerateClass(sqlTable);

        Console.WriteLine(cSharpClass);
    }
    public static string GenerateClassFromTable(this ISqlConnectionProvider sqlConnectionProvider,
                                                string schemaname, string tableName,
                                                string className = null)
    {
        className = className ?? tableName;
        var sqlTableReference = new SqlTableReference(sqlConnectionProvider, schemaname, tableName);
        var sqlTable          = SqlTableFactory.Create(sqlTableReference);

        return(CSharpClassGeneratorFromSqlTable.GenerateClass(sqlTable, className));
    }
Exemple #4
0
    public void CreateManyRandomClassesFromInformationSchema()
    {
        string outputText = String.Empty;
        var    randomSqlTableReferences = RandomTableSelector.GetRandomSqlTableReferences(SqlConnectionProviders.AdventureWorksDb, 400);

        foreach (var sqlTableReference in randomSqlTableReferences)
        {
            var sqlTable    = SqlTableFactory.Create(sqlTableReference);
            var cSharpClass = CSharpClassGeneratorFromSqlTable.GenerateClass(sqlTable);
            outputText += cSharpClass;
        }
        Console.WriteLine(outputText);
    }
Exemple #5
0
    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);
        });
    }