Beispiel #1
0
 public void ShouldReturnSavedQueryList()
 {
     var repo   = new SavedQueryFileFormatRepo();
     var path   = @"C:\Temp\PxWebComparerTest\ThreeQueryFile.txt";
     var result = repo.GetSavedQueryFileFormat(path);
 }
        public void Compare()
        {
            // get url for api site 1
            var serverAddress1 = _appSettingsHandler.ReadSetting("WebApiAddress1") + $"sq/";
            // get url for api site 2
            var serverAddress2 = _appSettingsHandler.ReadSetting("WebApiAddress2") + $"sq/";

            var queryTextListPath = _appSettingsHandler.ReadSetting("queryTextListPath");

            var resultFolder1          = _appSettingsHandler.ReadSetting("ResultFolder1") + "/SavedQuery/";
            var resultFolder2          = _appSettingsHandler.ReadSetting("ResultFolder2") + "/SavedQuery/";
            var compareResultFile      = _appSettingsHandler.ReadSetting("CompareResultFile");
            var fileRepo               = new FileCompareRepo();
            var compareResultModelList = new List <CompareResultModel>();

            var queryList = _repo.GetSavedQueryFileFormat(queryTextListPath);

            fileRepo.DeleteAllFilesInFolder(resultFolder1);
            fileRepo.DeleteAllFilesInFolder(resultFolder2);
            {
                foreach (var query in queryList)
                {
                    var compareResultModel = new CompareResultModel {
                        SavedQuery = query
                    };

                    var outputFormats = Enum.GetValues(typeof(OutputFormat)).Cast <OutputFormat>();

                    // Check if you can run the saved query at all on reference site
                    var res = _savedQueryService.GetService($"{serverAddress1}{query}");

                    if (res == null)
                    {
                        foreach (var outputFormat in outputFormats)
                        {
                            compareResultModel.UpdateModel(outputFormat, null);
                        }
                    }
                    else
                    {
                        foreach (var outputFormat in outputFormats)
                        {
                            bool saveQuery1;
                            bool saveQuery2;
                            bool?result;

                            if (outputFormat == OutputFormat.xlsx || outputFormat == OutputFormat.xlsx_doublecolumn)
                            {
                                saveQuery1 = _savedQueryService.GetAndSaveAsFile($"{serverAddress1}{query}.{outputFormat}",
                                                                                 $"{query}_{outputFormat}",
                                                                                 "xlsx", $"{resultFolder1}\\{query}\\");

                                saveQuery2 = _savedQueryService.GetAndSaveAsFile($"{serverAddress1}{query}.{outputFormat}",
                                                                                 $"{query}_{outputFormat}",
                                                                                 "xlsx", $"{resultFolder2}\\{query}\\");

                                Thread.Sleep(100);

                                if (saveQuery1 && saveQuery2)
                                {
                                    var resultList1 =
                                        _excelComparer.ReadExcelFile(
                                            $@"{resultFolder1}\{query}\{query}_{outputFormat}.xlsx");
                                    var resultList2 =
                                        _excelComparer.ReadExcelFile(
                                            $@"{resultFolder2}\{query}\{query}_{outputFormat}.xlsx");
                                    result = CompareArrayLists(resultList1, resultList2);
                                }
                                else
                                {
                                    result = null;
                                }
                            }
                            else
                            {
                                var res1 = _savedQueryService.GetService($"{serverAddress1}{query}.{outputFormat}");

                                var res2 = _savedQueryService.GetService($"{serverAddress2}{query}.{outputFormat}");

                                Thread.Sleep(100);

                                if (res1 != null && res2 != null)
                                {
                                    _savedQueryService.SaveToFile(res1, query, outputFormat.ToString(),
                                                                  $"{resultFolder1}\\{query}\\");
                                    _savedQueryService.SaveToFile(res2, query, outputFormat.ToString(),
                                                                  $"{resultFolder2}\\{query}\\");

                                    if (outputFormat == OutputFormat.html5_table)
                                    {
                                        fileRepo.DeleteFirstRowInFile($@"{resultFolder1}\{query}\{query}_{outputFormat}.txt");
                                        fileRepo.DeleteFirstRowInFile($@"{resultFolder2}\{query}\{query}_{outputFormat}.txt");
                                    }

                                    result = CompareSavedQueryResults(
                                        $@"{resultFolder1}\{query}\{query}_{outputFormat}.txt",
                                        $@"{resultFolder2}\{query}\{query}_{outputFormat}.txt");
                                }
                                else
                                {
                                    result = null;
                                }
                            }

                            compareResultModel.UpdateModel(outputFormat, result);
                        }
                    }
                    compareResultModelList.Add(compareResultModel);
                }

                fileRepo.DeleteFile(compareResultFile);
                fileRepo.SaveToFile(compareResultModelList, compareResultFile);
                var resultFile = fileRepo.ReadFromFile <CompareResultModel>(compareResultFile);
            }
        }