private async void RunTests() { EnableButtons(false); List <ConfigFile> lstConfigFiles = BaseTestCase.LoadConfigFile("config_file.json"); string _testcasetype = string.Empty; foreach (var item in lstConfigFiles) { try { _testcasetype = item.TestCaseType; string testResultString = string.Format(item.Purpose + "\r\n\r\n"); testCaseRunner = new TestCaseRunner(item.FilePath); testCaseRunner.TestCaseOutputEventHandler += TestCaseRunner_TestCaseOutputEventHandler; testCaseRunner.RunTestCases(); } catch (Exception ex) { await Dispatcher.InvokeAsync(new Action(() => TestResultVM.TestResultObservableCollection.Add(new TestCaseResult { Target = item.TestName, InputJsonFileName = item.FilePath, Result = "Fail", Description = ex.Message }))); } } EnableButtons(true); }
private static void RunTests(string configFileName) { List <ConfigFile> lstConfigFiles = BaseTestCase.LoadConfigFile(configFileName); string _testcasetype = string.Empty; foreach (var item in lstConfigFiles) { try { _testcasetype = item.TestCaseType; //string testResultString = string.Format(item.Purpose + "\r\n\r\n"); //Console.WriteLine(testResultString); // make configurable? //Replace curl with C# default httpWebRequest API testCaseRunner = new TestCaseRunner(item.FilePath); //testCaseRunner.PathToCurl = "curl.exe"; testCaseRunner.TestCaseOutputEventHandler += TestCaseRunner_TestCaseOutputEventHandler; //TODO: hook up string streaming testCaseRunner.RunTestCases(); //testResultString = string.Format(item.TestName + " test case status : {0} \r\n\r\n", testCaseRunner.DidAllTestCasesPass()); //Console.WriteLine(testResultString); } catch (Exception ex) { Console.WriteLine(string.Format("\t" + ex.Message + "\r\n\r\n")); } } Console.WriteLine("Do you want to export test case result? [yes/no]"); string option = Console.ReadLine(); if (option == "yes") { string filename = "TestCaseResult" + DateTime.Now.ToString("yyyy''MM''dd'T'HH''mm''ss") + ".csv"; if (itemList == null || itemList.Count == 0) { return; } var sb = new StringBuilder(); string csvHeaderRow = String.Join(",", typeof(TestCaseResult).GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(x => x.Name).ToArray <string>()) + Environment.NewLine; sb.AppendLine(csvHeaderRow); foreach (var data in itemList) { sb.AppendLine(data.Target + "," + data.ProxyURL + "," + data.ProxyType + "," + data.InputJsonFileName + "," + data.ExpectedStatusCode + "," + data.ActualStatusCode + "," + data.Result + "," + data.Description); } File.WriteAllText(filename, sb.ToString()); Console.WriteLine(string.Format("Test case data has been exported to {0} file in current directory", filename)); } }