From bca29f86334e52b67b0fb1ebb233f6d839b21e1b Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Tue, 29 Aug 2017 16:41:06 -0700 Subject: [PATCH 1/7] Parameterless execution of PSSwagger.LTF.ConsoleServer.exe + test module fixes --- .../PSSwagger.LTF.ConsoleServer.csproj | 4 ++ .../PSSwagger.LTF.ConsoleServer/Program.cs | 61 ++++++++++++++++--- .../PSSwagger.LTF.ConsoleServer/config.json | 2 + .../PSSwagger.LTF.ConsoleServer.csproj | 10 +++ .../vs-csproj/packages.config | 4 ++ .../PSSwagger.LiveTestFramework.Tests.psm1 | 4 +- 6 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/config.json create mode 100644 PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/vs-csproj/packages.config diff --git a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/PSSwagger.LTF.ConsoleServer.csproj b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/PSSwagger.LTF.ConsoleServer.csproj index de5da85..64e6192 100644 --- a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/PSSwagger.LTF.ConsoleServer.csproj +++ b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/PSSwagger.LTF.ConsoleServer.csproj @@ -10,5 +10,9 @@ + + + + \ No newline at end of file diff --git a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/Program.cs b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/Program.cs index 68fa4ee..5eb94eb 100644 --- a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/Program.cs +++ b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/Program.cs @@ -10,6 +10,7 @@ namespace PSSwagger.LTF.ConsoleServer using Lib.Models; using Lib.PowerShell; using Lib.ServiceTracing; + using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; @@ -20,7 +21,7 @@ class Program { static void Main(string[] args) { - ServerArgs serverArgs = new ServerArgs(args); + ServerArgs serverArgs = new ServerArgs().Parse("config.json").Parse(args).Validate(); NamedPipeServer namedPipe = new NamedPipeServer(serverArgs.LogPipeName); Logger logger = new Logger(namedPipe, namedPipe); if (serverArgs.Errors.Count > 0) @@ -77,7 +78,7 @@ static void Main(string[] args) } } } - + class ServerArgs { public List SpecificationPaths { get; set; } @@ -86,13 +87,19 @@ class ServerArgs public string LogPipeName { get; set; } public List Errors { get; set; } - public ServerArgs(string[] args) + public ServerArgs() { - this.LogPipeName = "psswagger-ltf-consoleserver"; - string lastArg = String.Empty; + this.Errors = new List(); this.SpecificationPaths = new List(); this.ExternalModules = new List(); - this.Errors = new List(); + this.LogPipeName = "psswagger-ltf-consoleserver"; + } + + public ServerArgs Parse(string[] args) + { + string lastArg = String.Empty; + bool resetSpecificationPaths = false; + bool resetExternalModules = false; foreach (string arg in args) { if (!arg.StartsWith("/")) @@ -103,15 +110,29 @@ public ServerArgs(string[] args) if (!arg.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { this.Errors.Add("Specification file is not a .json file."); - } else if (!File.Exists(arg)) + } + else if (!File.Exists(arg)) { this.Errors.Add(String.Format(CultureInfo.CurrentCulture, "Specification file does not exist: {0}", arg)); - } else + } + else { + if (!resetSpecificationPaths) + { + resetSpecificationPaths = true; + this.SpecificationPaths.Clear(); + } + this.SpecificationPaths.Add(arg); } break; case "extmodule": + if (!resetExternalModules) + { + resetExternalModules = true; + this.ExternalModules.Clear(); + } + this.ExternalModules.Add(arg); break; case "testmodule": @@ -125,16 +146,38 @@ public ServerArgs(string[] args) break; } lastArg = String.Empty; - } else + } + else { lastArg = arg.Substring(1); } } + return this; + } + + public ServerArgs Parse(string jsonFilePath) + { + ServerArgs ret; + if (File.Exists(jsonFilePath)) + { + ret = JsonConvert.DeserializeObject(File.ReadAllText(jsonFilePath)); + } else + { + ret = new ServerArgs(); + } + + return ret; + } + + public ServerArgs Validate() + { if (String.IsNullOrEmpty(this.ModulePath)) { this.Errors.Add("No test module path specified."); } + + return this; } } } diff --git a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/config.json b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/config.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/config.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/vs-csproj/PSSwagger.LTF.ConsoleServer.csproj b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/vs-csproj/PSSwagger.LTF.ConsoleServer.csproj index e07b498..627a09f 100644 --- a/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/vs-csproj/PSSwagger.LTF.ConsoleServer.csproj +++ b/PSSwagger.LiveTestFramework/src/PSSwagger.LTF.ConsoleServer/vs-csproj/PSSwagger.LTF.ConsoleServer.csproj @@ -32,6 +32,10 @@ 4 + + packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll + True + @@ -43,6 +47,9 @@ + + PreserveNewest + @@ -54,6 +61,9 @@ PSSwagger.LTF.Lib + + +