private static void _checkConfig(Config config) { if (config.ReportType != ReportType.None && string.IsNullOrEmpty(config.ReportFileLocation)) { throw new Exception("--rn:[report file name] flag is required with --rt flag"); } if (!Directory.Exists(config.Location)) { throw new Exception("--loc: location is invalid, directory does not exist"); } if (!config.Environment.Any()) { //load all the tests if (!Directory.Exists(config.EnvLocation)) { throw new Exception("test location does not have a valid env directory"); } foreach (var file in Directory.GetFiles(config.EnvLocation)) { config.Environment.Add(file); } } if (!config.Test.Any()) { if (!Directory.Exists(config.TestLocation)) { throw new Exception("test location does not have a valid 'tests' directory"); } foreach (var file in Directory.GetFiles(config.TestLocation)) { config.Test.Add(file); } } }
public static Config Load(string[] args) { var config = new Config(); foreach (var arg in args) { var key = arg.Substring(0, 3); var val = arg.Substring(4); var argKv = new[] {key, val}; if (argKv.Length == 2) { var v = argKv[1]; switch (argKv[0]) { case "--l": config.Location = v; break; case "--e": config.Environment.Add(v); break; case "--t": config.Test.Add(v); break; case "--i": int iteration; if (int.TryParse(v, out iteration)) { if (iteration < 1 || iteration > 10) { iteration = 1; } } else { iteration = 1; } config.Iteration = iteration; break; case "--T": switch (v) { case "json": config.ReportType = ReportType.Json; config.ReportCode = string.Empty; config.ReportFileExtension = ".json"; break; case "html": config.ReportType = ReportType.Html; config.ReportCode = "-H"; config.ReportFileExtension = ".html"; break; case "xml": config.ReportType = ReportType.Xml; config.ReportCode = "-t"; config.ReportFileExtension = ".xml"; break; default: config.ReportType = ReportType.None; break; } break; case "--n": config.ReportFileLocation = v; break; case "--N": config.NewmanCommand = v; break; } } } _checkConfig(config); return config; }