public JsonResult DestCopyTest(List <jsonResp> testcase, string testPlan, string testSuit) { CreateTest t1 = new CreateTest(); foreach (var item in testcase) { WorkItemsClass testcaseItem = logic.TestCaseRetrive(item.id); //getting the details of the testcase with the ID //after we get the details from of the id,we should create a new testcase TestCaseResponseModel testResponse = t1.TestCaseCreate(testcaseItem); if (testResponse != null) { t1.AddtoTestCaseToTestSuit(testPlan, testSuit, testResponse.id.ToString()); } } bool result = false; if (CheckValid.AddTestcase == true) { result = true; } else { result = false; } return(Json(result, JsonRequestBehavior.AllowGet)); }
private async Task <TestCaseResponseModel> ParseTestCase(SubmissionGetFirstFailModel submission) { var firstFailResult = submission.FirstFailTestCase; var configs = await _adminSettingCacheBusiness.GetCache(); var input = "Test case has not downloaded!"; var output = "Test case has not downloaded!"; var testSeq = firstFailResult == null ? int.MaxValue : firstFailResult.SeqNum; var inputPath = Path.Combine(ApplicationConfigs.SystemInfo.TestCaseFolder, Path.Combine(submission.ProblemCode, $"{testSeq}.in")); var outputPath = Path.Combine(ApplicationConfigs.SystemInfo.TestCaseFolder, Path.Combine(submission.ProblemCode, $"{testSeq}.out")); if (File.Exists(inputPath)) { input = FileUltils.ReadFileAllText(inputPath); } if (File.Exists(outputPath)) { output = FileUltils.ReadFileAllText(outputPath); } if (configs?.TestCaseLimitation != null) { if (input.Length > configs.TestCaseLimitation) { input = input.Substring(0, configs.TestCaseLimitation.Value) .Replace("\r\n", "\n").Replace("\n", "\r\n") + "..."; } if (output.Length > configs.TestCaseLimitation) { output = output.Substring(0, configs.TestCaseLimitation.Value) .Replace("\r\n", "\n").Replace("\n", "\r\n") + "..."; } } var model = new TestCaseResponseModel { SubmissionId = submission.SubmissionSpojId, ProblemCode = submission.ProblemCode, ResultName = firstFailResult == null?Enums.ResultType.Accepted.GetDisplayName() : firstFailResult.Result.GetDisplayName(), TestCaseSeq = firstFailResult == null ? -1 : firstFailResult.SeqNum, Input = input, Output = output }; return(model); }
public TestCaseResponseModel TestCaseCreate(WorkItemsClass testcases) { TestCaseResponseModel Result = new TestCaseResponseModel(); try { string testName = testcases.fields.Title; string jsonString = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~") + @"\Jsons\TestCaseJson.json"); jsonString = jsonString.Replace("$name$", testName); string api = string.Format("https://dev.azure.com/{0}/{1}/_apis/wit/workitems/${2}?api-version=5.1", Org.OrganizationName, Org.ProjectName, "Test Case"); using (var client = new HttpClient()) { var jsonContent = new StringContent(jsonString, Encoding.UTF8, "application/json-patch+json");//"application/json"); var method = new HttpMethod("POST"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Org.pat); var request = new HttpRequestMessage(method, api) { Content = jsonContent }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { var obj = response.Content.ReadAsStringAsync().Result; var Message = response.Content.ReadAsStringAsync(); Result = JsonConvert.DeserializeObject <TestCaseResponseModel>(obj); return(Result); } else { var errorMessage = response.Content.ReadAsStringAsync(); return(Result); } } return(Result); } catch { return(Result); } }