public static BenchmarkDto DbEntityToModel([NotNull] Benchmark entity) { var result = new BenchmarkDto() { Id = entity.Id, BenchmarkName = entity.Name, Description = entity.Description, HtmlPreparationCode = entity.HtmlPreparationCode, OwnerId = entity.OwnerId, ScriptPreparationCode = entity.ScriptPreparationCode, TestCases = new List <TestCaseDto>(), WhenCreated = entity.WhenCreated, Version = entity.Version }; foreach (var test in entity.BenchmarkTest) { var testCase = new TestCaseDto() { TestCaseName = test.TestName, BenchmarkCode = test.BenchmarkText }; result.TestCases.Add(testCase); } return(result); }
public async Task DeleteTestCase(TestCaseDto testCaseDto) { var testCase = Mapper.Map <TestCase>(testCaseDto); _repo.Delete <TestCase>(testCase); await _repo.SaveAll(); }
public async Task <bool> AddTestCase(TestCaseDto testCaseDto) { var testCase = Mapper.Map <TestCase>(testCaseDto); _repo.Add <TestCase>(testCase); return(await _repo.SaveAll()); }
private HttpContent BuildContent(TestCaseDto testCase) { if (testCase.ContentType == ContentTypes.Json || testCase.ContentType == ContentTypes.FormUrlencoded) { return(new StringContent(testCase.Data, Encoding.UTF8, testCase.ContentType)); } return(null); }
public async Task <HttpResponseMessage> SendAsync(string host, TestCaseDto testCase) { var httpMethod = new HttpMethod(testCase.HttpMethod); var message = new HttpRequestMessage(httpMethod, BuildUrl(testCase)) { Content = BuildContent(testCase) }; //message.Headers.Add("Authorization", IOCContainer.Resolve<ITokenAccessor>().Get()); var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(host); return(await client.SendAsync(message)); }
private string BuildUrl(TestCaseDto testCase) { var url = testCase.Url; if (new Regex("{\\d+}").IsMatch(url)) { return(string.Format(url, testCase.Data.Split(','))); } if (testCase.ContentType == ContentTypes.Url) { url = $"{url}?{testCase.Data}"; } return(url); }
// TODO: Unit tests public static List <TestCaseDto> ReadTestCases([NotNull] HttpRequest request) { var testCases = new List <TestCaseDto>(); if (!request.HasFormContentType) { return(testCases); } var indexes = new HashSet <int>(); // list of test case indexes IFormCollection form = request.Form; foreach (var key in form.Keys) { if (key.StartsWith("TestCases[")) { var match = TestCaseKeyRegex.Match(key); if (!match.Success || match.Groups.Count != 2) { continue; } int index = 0; if (int.TryParse(match.Groups[1].Value, out index)) { indexes.Add(index); } } } foreach (var idx in indexes) { string nameKey = $"TestCases[{idx}].TestCaseDtoName"; string codeKey = $"TestCases[{idx}].BenchmarkCode"; if (form.ContainsKey(nameKey) && form.ContainsKey(codeKey)) { var name = form[nameKey]; var code = form[codeKey]; var testCase = new TestCaseDto() { BenchmarkCode = code, TestCaseName = name }; testCases.Add(testCase); } } return(testCases); }
public async Task DeleteTestCase_Failure_NotFoundResponse() { TestCaseDto returnObj = null; //Arrange _testCaseServiceMock.Setup(service => service.GetTestCase(It.IsAny <int>())) .ReturnsAsync(returnObj); // ACT var response = (IActionResult)await _controller.DeleteTestCase(12); var result = (StatusCodeResult)response; //Assert Assert.IsNotNull(result); _testCaseServiceMock.Verify(t => t.GetTestCase(It.IsAny <int>()), Times.Once); _testCaseServiceMock.Verify(t => t.DeleteTestCase(It.IsAny <TestCaseDto>()), Times.Never); Assert.IsTrue(result.StatusCode == (int)HttpStatusCode.NotFound); }
public async Task <IActionResult> AddTestCase([FromBody] TestCaseDto testCaseDto) { if (ModelState.IsValid) { var isSuccess = await _testCaseService.AddTestCase(testCaseDto); if (isSuccess) { return(StatusCode((int)HttpStatusCode.Created)); } else { return(StatusCode((int)HttpStatusCode.BadRequest)); } } else { return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = ModelState.Values.SelectMany(x => x.Errors).ToList() })); } }
static async Task Main(string[] args) { string inputPath = args[0]; string outputPath = args[1]; using (var application = AbpApplicationFactory.Create <BugdiggerConsoleHostModule>(option => { option.UseAutofac(); })) { application.Initialize(); var xmlService = application.ServiceProvider.GetService <XmlService>(); var testExecAppService = application.ServiceProvider.GetService <ITestExecAppService>(); var project = xmlService.ReadStr <Project>(File.ReadAllText(inputPath)); var testResults = new List <TestResultDto>(); foreach (var testflow in project.Testflow) { foreach (var step in testflow.step) { for (int i = 0; i < step.exectimes; i++) { if (step.delaytime > 0) { await Task.Delay(step.delaytime); } string configpath = ""; if (step.xmlPath != "") { configpath = step.xmlPath + "/" + step.xmlname; Console.WriteLine(configpath); } else { int index = inputPath.LastIndexOf("/"); configpath = inputPath.Substring(0, index + 1) + "/" + step.xmlname; Console.WriteLine(configpath); } string text = File.ReadAllText(configpath); var testCaseDto = new TestCaseDto() { Name = step.xmlname, Script = text }; var testResult = await testExecAppService.CreateAsync(testCaseDto); if (testResult != null) { testResults.AddRange(testResult); } } } } if (testResults.Count == 0) { Console.WriteLine("No result!"); return; } File.WriteAllText(outputPath, JsonConvert.SerializeObject(testResults)); Console.WriteLine("Auto Test Finish!"); } }