예제 #1
0
        public static void CreateCountQuery(List <Dictionary <string, string> > configList)
        {
            if (Configuration.GenerateCountSmokeTests)
            {
                var data = TablesDefinitions.GetTablesDefinitions();

                for (int i = 0; i < data.Rows.Count; i++)
                {
                    var tableSchemaIteration = CompareQuerySqlServer.TableSchemaIteration(data, i, out var tableNameIteration);
                    var(createTest, domain, comment, whereClause, orderByCluse, aggregateByClause) = ReadConfigurationFromXlsx.CheckIfTableInExcel(configList, tableSchemaIteration, tableNameIteration);
                    if (createTest)
                    {
                        Logger.Debug("Skip iteration");
                        continue;
                    }

                    if (i + 1 < data.Rows.Count && tableNameIteration == data.Rows[i + 1]["TABLE_NAME"].ToString() &&
                        tableSchemaIteration == data.Rows[i + 1]["TABLE_SCHEMA"].ToString())
                    {
                        Logger.Debug("Skip iteration");
                        continue;
                    }

                    var folder     = CopyConfigFiles.CreateFolderForTest(tableSchemaIteration, tableNameIteration, "1.Count");
                    var countQuery = TablesDefinitions.CreateSmokeCountQuery(tableSchemaIteration, tableNameIteration);
                    CopyConfigFiles.CreateTestDefinitions(folder, countQuery, tableSchemaIteration, tableNameIteration, "Smoke_", "ActualTable.sql", "from_file_sql.xml");
                    CopyConfigFiles.CreateTestDefinitions(folder, countQuery, tableSchemaIteration, tableNameIteration, "Smoke_", "ExpectedTable.sql");
                }
            }
        }
        public static void CreateCompareQuery(List <Dictionary <string, string> > configList)
        {
            DataTable data = new DataTable();

            if (Configuration.GenerateCompareFetchTests || Configuration.GenerateCompareMinusTests)
            {
                data = TablesDefinitions.GetTablesDefinitions();
            }

            var columnsDictionary = new List <Tuple <string, string> >();

            for (int i = 0; i < data.Rows.Count; i++)
            {
                var tableSchemaIteration = TableSchemaIteration(data, i, out var tableNameIteration);
                var(createTest, domain, comment, whereClause, orderByCluse, aggregateByClause) = ReadConfigurationFromXlsx.CheckIfTableInExcel(configList, tableSchemaIteration, tableNameIteration);
                if (createTest)
                {
                    continue;
                }

                columnsDictionary.Add(Tuple.Create(data.Rows[i]["COLUMN_NAME"].ToString(), data.Rows[i]["DATA_TYPE"].ToString()));
                string nextTable  = null;
                string nextSchema = null;
                if (i + 1 < data.Rows.Count)
                {
                    nextTable  = data.Rows[i + 1]["TABLE_NAME"].ToString();
                    nextSchema = data.Rows[i + 1]["TABLE_SCHEMA"].ToString();
                }

                if (tableNameIteration != nextTable || tableSchemaIteration != nextSchema)
                {
                    var queryDefinition = CreateQuery(tableSchemaIteration, tableNameIteration, columnsDictionary, comment, whereClause, orderByCluse, aggregateByClause);

                    for (int j = 0; j < queryDefinition.Count; j++)
                    {
                        if (!queryDefinition[j].QueryAggregate)
                        {
                            if (Configuration.GenerateCompareFetchTests)
                            {
                                var folderFetch = CopyConfigFiles.CreateFolderForTest(tableSchemaIteration, tableNameIteration, "2.RowByRow");
                                CopyConfigFiles.CreateTestDefinitions(folderFetch, queryDefinition[j].QueryFetchBranch, tableSchemaIteration, tableNameIteration, "Fetch_", "ActualTable.sql", "from_file_sql.xml");
                                CopyConfigFiles.CreateTestDefinitions(folderFetch, queryDefinition[j].QueryFetchLive, tableSchemaIteration, tableNameIteration, "Fetch_", "ExpectedTable.sql");
                            }

                            if (Configuration.GenerateCompareMinusTests)
                            {
                                var folderMinus = CopyConfigFiles.CreateFolderForTest(tableSchemaIteration, tableNameIteration, "3.MinusCompare");
                                CopyConfigFiles.CreateTestDefinitions(folderMinus, queryDefinition[j].QueryMinusBranch, tableSchemaIteration, tableNameIteration, "Minus_", "ActualTable.sql", "minus_from_file_sql.xml");
                                CopyConfigFiles.CreateTestDefinitions(folderMinus, queryDefinition[j].QueryMinusLive, tableSchemaIteration, tableNameIteration, "Minus_", "ExpectedTable.sql");
                            }
                        }
                        else
                        {
                            if (Configuration.GenerateCompareFetchTests)
                            {
                                var folderFetch = CopyConfigFiles.CreateFolderForTest(tableSchemaIteration, tableNameIteration, "4.FetchAggregateGroupBy", queryDefinition[j].ColumnName);
                                CopyConfigFiles.CreateTestDefinitions(folderFetch, queryDefinition[j].QueryFetchBranch, tableSchemaIteration, tableNameIteration, "Fetch_", "ActualTable.sql", "from_file_sql.xml");
                                CopyConfigFiles.CreateTestDefinitions(folderFetch, queryDefinition[j].QueryFetchLive, tableSchemaIteration, tableNameIteration, "Fetch_", "ExpectedTable.sql");
                            }

                            if (Configuration.GenerateCompareMinusTests)
                            {
                                var folderMinus = CopyConfigFiles.CreateFolderForTest(tableSchemaIteration, tableNameIteration, "5.MinusAggregateGroupBy", queryDefinition[j].ColumnName);
                                CopyConfigFiles.CreateTestDefinitions(folderMinus, queryDefinition[j].QueryMinusBranch, tableSchemaIteration, tableNameIteration, "Minus_", "ActualTable.sql", "minus_from_file_sql.xml");
                                CopyConfigFiles.CreateTestDefinitions(folderMinus, queryDefinition[j].QueryMinusLive, tableSchemaIteration, tableNameIteration, "Minus_", "ExpectedTable.sql");
                            }
                        }
                    }

                    columnsDictionary.Clear();
                }
            }
        }