Skip to content

Commit

Permalink
show before/after output in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gicastel committed Dec 1, 2022
1 parent 1ab813b commit b64327c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
9 changes: 6 additions & 3 deletions src/qest/Connectors/MsSqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,15 @@ private async Task RunScriptAsync(Scripts scripts)
var transaction = Connection.BeginTransaction();
try
{
scripts.ActualScripts = new();
foreach (var item in scripts)
{
string script = item.Compact(currentTest.Variables);
if (script.Length > 0)
foreach (string innerScript in item.GetValues())
{
var cmd = new SqlCommand(script, Connection, transaction);
string actualScript = (string)innerScript.ReplaceVarsInParameter(currentTest.Variables);
scripts.ActualScripts.Add(actualScript);
SqlCommand cmd = new(actualScript, Connection, transaction);
cmd.CommandType = CommandType.Text;
await cmd.ExecuteNonQueryAsync();
}
}
Expand Down
36 changes: 20 additions & 16 deletions src/qest/Models/Script.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using YamlDotNet.Serialization;

Expand All @@ -10,33 +11,34 @@ public class Script
public ScriptType Type { get; set; }
public List<string> Values { get; set; }

public string Compact(Dictionary<string, object>? variables)
public IEnumerable<string> GetValues()
{
if (Values == null)
throw new ArgumentNullException(nameof(Values));

switch (this.Type)
foreach (var value in Values)
{
case ScriptType.Inline:
return string.Join(";", Values).ReplaceVars(variables);
switch (this.Type)
{
case ScriptType.Inline:
yield return value;
break;
case ScriptType.File:

case ScriptType.File:
List<string> list = new List<string>();
foreach (var item in Values)
{
if (File.Exists(item))
if (File.Exists(value))
{
using var sr = new StreamReader(item);
using var sr = new StreamReader(value);
string data = sr.ReadToEnd();
list.Add(data);
yield return data;
}
else
throw new FileNotFoundException(null, item);
}
return string.Join(";", list).ReplaceVars(variables);
default:
throw new ArgumentException(nameof(Type));
throw new FileNotFoundException(null, value);
break;
default:
throw new ArgumentException(nameof(Type));
}
}

}
}

Expand All @@ -48,6 +50,8 @@ public enum ScriptType

public class Scripts : List<Script>
{
[YamlIgnore]
public List<string>? ActualScripts { get; set; }
[YamlIgnore]
public bool Result => ResultException is null;
[YamlIgnore]
Expand Down
15 changes: 15 additions & 0 deletions src/qest/Visualizers/ConsoleVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,24 @@ private void EvaluateScript(string scope, Scripts scripts)
LogHierarchy.Add(objName);

if (scripts.Result)
{
if (Verbose)
for (int i = 0; i < scripts.ActualScripts?.Count; i++)
{
string? item = scripts.ActualScripts[i];
LogConsole(item.EscapeAndAddStyles(objectStyle_l3));
}

LogConsole("OK".EscapeAndAddStyles(okStyle));
}
else
{
for (int i = 0; i < scripts.ActualScripts?.Count; i++)
{
string? item = scripts.ActualScripts[i];
LogConsoleError(item.EscapeAndAddStyles(objectStyle_l3));
}

LogException(scripts.ResultException!);
Pass = false;
}
Expand Down
13 changes: 13 additions & 0 deletions src/qest/Visualizers/TreeVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,24 @@ private void EvaluateScript(string scope, Scripts scripts, TreeNode root)

if (scripts.Result)
{
if (Verbose)
for (int i = 0; i < scripts.ActualScripts?.Count; i++)
{
string? item = scripts.ActualScripts[i];
scriptsNode.AddNode(new Markup(item.EscapeAndAddStyles(objectStyle_l3)));
}

scriptsNode.AddNode("OK".EscapeAndAddStyles(okStyle));
root.AddOutputNode(scriptsNode, Verbose);
}
else
{
for (int i = 0; i < scripts.ActualScripts?.Count; i++)
{
string? item = scripts.ActualScripts[i];
scriptsNode.AddNode(new Markup(item.EscapeAndAddStyles(objectStyle_l3)));
}

scriptsNode.AddExceptionNode(scripts.ResultException!);
root.AddNode(scriptsNode);
Pass = false;
Expand Down

0 comments on commit b64327c

Please sign in to comment.