diff --git a/src/qest/Connectors/MsSqlConnector.cs b/src/qest/Connectors/MsSqlConnector.cs index 267ab35..41ba390 100644 --- a/src/qest/Connectors/MsSqlConnector.cs +++ b/src/qest/Connectors/MsSqlConnector.cs @@ -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(); } } diff --git a/src/qest/Models/Script.cs b/src/qest/Models/Script.cs index 9b6db13..f4b0f0f 100644 --- a/src/qest/Models/Script.cs +++ b/src/qest/Models/Script.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.IO; using YamlDotNet.Serialization; @@ -10,33 +11,34 @@ public class Script public ScriptType Type { get; set; } public List Values { get; set; } - public string Compact(Dictionary? variables) + public IEnumerable 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 list = new List(); - 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)); + } } + } } @@ -48,6 +50,8 @@ public enum ScriptType public class Scripts : List