Skip to content

Commit

Permalink
verbose flag now shows executed command
Browse files Browse the repository at this point in the history
  • Loading branch information
gicastel committed Nov 21, 2022
1 parent 27b4e95 commit 2bf5390
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
21 changes: 18 additions & 3 deletions src/qest/Connectors/MsSqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,38 @@ private void RunTestStep(TestStep step)
SqlCommand testCmd = new(step.Command.CommandText, Connection);
testCmd.CommandType = CommandType.StoredProcedure;

step.Command.ActualParameters = new();

// add input pars
if (step.Command.Parameters != null)
foreach (var input in step.Command.Parameters)
{
testCmd.Parameters.AddWithValue($"@{input.Key}", input.Value?.ReplaceVarsInParameter(currentTest.Variables));
}
string parName = "@" + input.Key;
var parValue = input.Value?.ReplaceVarsInParameter(currentTest.Variables);
testCmd.Parameters.AddWithValue(parName, parValue);

string currentPar = parName + " = ";
if (parValue is null)
currentPar+= "NULL";
else
currentPar+= $"'{parValue}'";

step.Command.ActualParameters.Add(currentPar);
}

// add output pars
List<SqlParameter> outPars = new();
if (step.Results != null)
{
if (step.Results.OutputParameters != null)
foreach (var output in step.Results.OutputParameters)
{
var outPar = testCmd.Parameters.Add($"@{output.Name}", MapQestTypeToSqlType(output.Type));
string parName = "@" + output.Name;
var outPar = testCmd.Parameters.Add(parName, MapQestTypeToSqlType(output.Type));
outPar.Direction = ParameterDirection.Output;
outPars.Add(outPar);

step.Command.ActualParameters.Add(parName + " OUTPUT");
}

// add rc if exists
Expand Down
2 changes: 2 additions & 0 deletions src/qest/Models/TestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class TestCommand
public string CommandText { get; set; }
public Dictionary<string, object>? Parameters { get; set; }

[YamlIgnore]
public List<string> ActualParameters { get; set; }
[YamlIgnore]
public bool Result => ResultException is null;
[YamlIgnore]
Expand Down
12 changes: 9 additions & 3 deletions src/qest/Visualizers/ConsoleVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ private async Task<bool> RunSingleTestAsync()

private void EvaluateTestStep(TestStep step, Dictionary<string, object>? variables)
{

LogHierarchy.Add("Command");
string actualCommand = $"{step.Command.CommandText} {string.Join(", ", step.Command.ActualParameters)}";
if (!step.Command.Result)
{
LogHierarchy.Add("Command");
LogConsoleError(actualCommand.EscapeAndAddStyles(objectStyle_l3));
LogException(step.Command.ResultException);
LogHierarchy.RemoveLast();
Pass = false;
return;
}
LogConsole(actualCommand.EscapeAndAddStyles(objectStyle_l3), Verbose);
LogHierarchy.RemoveLast();

if (step.Results != null)
{
Expand Down Expand Up @@ -291,8 +296,9 @@ private void EvaluateScript(string scope, Scripts scripts)

private void LogException(Exception ex)
{
string exTitle = "Exception".EscapeAndAddStyles(errorStyle);
string prfx = string.Join(consoleSeparator, LogHierarchy);
AnsiConsole.MarkupLine(prfx);
AnsiConsole.MarkupLine($"{prfx}{consoleSeparator}{exTitle}");
AnsiConsole.WriteException(ex);
}

Expand All @@ -306,7 +312,7 @@ private void LogConsole(string message, bool forceOutput = false)
}

private void LogConsoleError(string message) => LogConsole(message, true);

}

file static class ExtensionMethods
Expand Down
7 changes: 6 additions & 1 deletion src/qest/Visualizers/TreeVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ private async Task RunSingleTestAsync(TreeNode testNode)

private void EvaluateTestStep(TestStep step, Dictionary<string, object>? variables, TreeNode testCaseNode)
{

var commandNode = NewMarkupTreeNode("Command");
string actualCommand = $"{step.Command.CommandText} {string.Join(", ", step.Command.ActualParameters)}";
commandNode.AddNode(actualCommand.EscapeAndAddStyles(objectStyle_l3));
if (!step.Command.Result)
{
var commandNode = testCaseNode.AddNode("Command");
commandNode.AddExceptionNode(step.Command.ResultException);
testCaseNode.AddNode(commandNode);
Pass = false;
return;
}
testCaseNode.AddOutputNode(commandNode, Verbose);

if (step.Results != null)
{
Expand Down

0 comments on commit 2bf5390

Please sign in to comment.