public static int AssertStandardExcelSuccessConditions(SystemExecutionOutput systemExecutionOutput) { if (systemExecutionOutput == null) { throw new ArgumentNullException(nameof(systemExecutionOutput)); } Assert.Matches("Excel generation :", systemExecutionOutput.StandardOutput); var sheetCount = ReadSheetCountFromSpreadsheet(systemExecutionOutput.OutputFileContent); Assert.True(sheetCount > 0); return(sheetCount); }
public static int AssertStandardCsvSuccessConditions(SystemExecutionOutput systemExecutionOutput) { if (systemExecutionOutput == null) { throw new ArgumentNullException(nameof(systemExecutionOutput)); } Assert.Matches("CSV generation :", systemExecutionOutput.StandardOutput); var fileCount = ReadCsvFileCountFromZipArchive(systemExecutionOutput.OutputFileContent); Assert.True(fileCount > 0); return(fileCount); }
public static void AssertStandardSuccessConditions(SystemExecutionOutput systemExecutionOutput) { if (systemExecutionOutput == null) { throw new ArgumentNullException(nameof(systemExecutionOutput)); } Assert.Equal(0, systemExecutionOutput.ExitCode); Assert.Matches("Query results :", systemExecutionOutput.StandardOutput); Assert.Matches("Merged results with", systemExecutionOutput.StandardOutput); Assert.Matches(" generation :", systemExecutionOutput.StandardOutput); Assert.DoesNotMatch("FATAL", systemExecutionOutput.StandardOutput); Assert.NotNull(systemExecutionOutput.OutputFileContent); Assert.True(systemExecutionOutput.OutputFileContent.Length > 0); Assert.True(systemExecutionOutput.OutputFileContent.Length >= 2); // The file is actually a ZIP file. ZIP files start with magic header "PK" {80;75}. Assert.Equal(80, systemExecutionOutput.OutputFileContent[0]); Assert.Equal(75, systemExecutionOutput.OutputFileContent[1]); }
public static SystemExecutionOutput RunQueryMultiDbExecution(QueryMultiDbArgumentStringBuilder argumentStringBuilder, bool createOutputFileBeforeExecution = false) { if (argumentStringBuilder == null) { throw new ArgumentNullException(nameof(argumentStringBuilder)); } var temporaryDirectory = GetTemporaryDirectory(); var outputFilename = Guid.NewGuid().ToString(); var outputFile = Path.Combine(temporaryDirectory, outputFilename); argumentStringBuilder.OutputFile = outputFile; if (createOutputFileBeforeExecution) { using (var sw = File.CreateText(outputFile)) { sw.WriteLine("Test file created before execution."); } } var arguments = argumentStringBuilder.ToString(); var startInfo = new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = false, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, FileName = ExecutableResolver.GetQueryMultiDbExecutablePath(QueryMultiDbFilename, RelativeExecutablePath), Arguments = arguments }; SystemExecutionOutput systemExecutionOutput; using (var process = Process.Start(startInfo)) { if (process == null) { throw new Exception(); } string standardOutput; using (var standardOutputReader = process.StandardOutput) { standardOutput = standardOutputReader.ReadToEnd(); } string standardError; using (var standardErrorReader = process.StandardError) { standardError = standardErrorReader.ReadToEnd(); } process.WaitForExit(); var exitCode = process.ExitCode; byte[] fileContent = null; try { var path = outputFile; fileContent = File.ReadAllBytes(path); SafeCreateDirectory(RelativeTestResultsDirectory); var extension = argumentStringBuilder.Exporter == "csv" ? ".zip" : ".xlsx"; File.Move(path, RelativeTestResultsDirectory + outputFilename + extension); } catch { // Ignored because fileContent being null is fine in this case. It will be asserted later. throw; } systemExecutionOutput = new SystemExecutionOutput(exitCode, standardOutput, standardError, fileContent); } DeleteDirectory(temporaryDirectory); return(systemExecutionOutput); }