public async Task <IActionResult> CreateTestRunAvailabilityAsync([FromBody] TestRunAvailabilityDto testRunAvailabilityDto) { if (testRunAvailabilityDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var testRunAvailability = Mapper.Map <TestRunAvailability>(testRunAvailabilityDto); var result = await _meissaRepository.InsertWithSaveAsync(testRunAvailability); var resultDto = Mapper.Map <TestRunAvailabilityDto>(result); return(Ok(resultDto)); }
public async Task <IActionResult> CreateTestAgentAsync([FromBody] TestAgentDto testAgentDto) { if (testAgentDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var testAgent = Mapper.Map <TestAgent>(testAgentDto); var result = await _meissaRepository.InsertWithSaveAsync(testAgent).ConfigureAwait(false); var resultDto = Mapper.Map <TestAgentDto>(result); return(Ok(resultDto)); }
public async Task <IActionResult> CreateTestAgentRunAsync([FromBody] TestAgentRunDto logDto) { if (logDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var log = Mapper.Map <TestAgentRun>(logDto); var result = await _meissaRepository.InsertWithSaveAsync(log); var resultDto = Mapper.Map <TestAgentRunDto>(result); return(Ok(resultDto)); }
public async Task <IActionResult> CreateLogAsync([FromBody] LogDto logDto) { if (logDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var log = Mapper.Map <Log>(logDto); var result = await _meissaRepository.InsertWithSaveAsync(log).ConfigureAwait(false); var resultDto = Mapper.Map <LogDto>(result); return(Ok(resultDto)); }
public async Task <IActionResult> UpdateTestCaseExecutionHistoryAsync([FromBody] List <TestCaseRun> testCaseRuns) { try { Debug.WriteLine("##### Start UpdateTestCaseExecutionHistory"); DateTime startTime = DateTime.Now; var existingTestCasesHistory = _meissaRepository.GetAllQuery <TestCaseHistory>().Where(x => testCaseRuns.Any(y => y.FullName.Equals(x.FullName))).ToList(); var testCaseHistoryEntries = _meissaRepository.GetAllQuery <TestCaseHistoryEntry>(); foreach (var testCaseRun in testCaseRuns) { if (existingTestCasesHistory.Any(x => x.FullName.Equals(testCaseRun.FullName))) { var existingTestCaseHistory = existingTestCasesHistory.FirstOrDefault(x => x.FullName.Equals(testCaseRun.FullName)); // Creates the new test case history entry for the current run. if (existingTestCaseHistory != null) { var testCaseHistoryEntry = new TestCaseHistoryEntry { AvgDuration = testCaseRun.Duration, TestCaseHistoryId = existingTestCaseHistory.TestCaseHistoryId, }; _meissaRepository.Insert(testCaseHistoryEntry); // Get all previous runs for the test and add to the list the new entry. var allCurrentTestCaseHistoryEntries = testCaseHistoryEntries.Where(x => x.TestCaseHistoryId.Equals(existingTestCaseHistory.TestCaseHistoryId)).ToList(); allCurrentTestCaseHistoryEntries.Add(testCaseHistoryEntry); } // Calculate the new average duration for the current tests based on the new entry. double newAverageDurationTicks = testCaseHistoryEntries.Average(x => x.AvgDuration.Ticks); var newAverageDuration = new TimeSpan(Convert.ToInt64(newAverageDurationTicks)); // Update the test case history info. if (existingTestCaseHistory != null) { existingTestCaseHistory.AvgDuration = newAverageDuration; existingTestCaseHistory.LastUpdatedTime = DateTime.Now; _meissaRepository.Update(existingTestCaseHistory); } } else { // If no entries exist, we create the history test case and a new history entry. var testCaseHistoryDto = new TestCaseHistory() { FullName = testCaseRun.FullName, LastUpdatedTime = DateTime.Now, AvgDuration = testCaseRun.Duration, }; testCaseHistoryDto = await _meissaRepository.InsertWithSaveAsync(testCaseHistoryDto); var testCaseHistoryEntry = new TestCaseHistoryEntry { AvgDuration = testCaseRun.Duration, TestCaseHistoryId = testCaseHistoryDto.TestCaseHistoryId, }; _meissaRepository.Insert(testCaseHistoryEntry); } } await _meissaRepository.SaveAsync(); DateTime endTime = DateTime.Now; Debug.WriteLine($"##### End UpdateTestCaseExecutionHistory for {endTime - startTime}"); return(Ok()); } catch (Exception ex) { _logger.LogCritical("Exception while updating test cases execution history.", ex); return(StatusCode(500, "A problem happened while handling your request.")); } }
public async Task <IActionResult> UpdateTestCaseExecutionHistoryAsync([FromBody] List <TestCaseRun> testCaseRuns) { try { var existingTestCasesHistory = _meissaRepository.GetAllQuery <TestCaseHistory>().AsEnumerable().Where(x => testCaseRuns.Any(y => y.FullName.Equals(x.FullName))).ToList(); var testCaseHistoryEntries = _meissaRepository.GetAllQuery <TestCaseHistoryEntry>(); foreach (var testCaseRun in testCaseRuns) { if (existingTestCasesHistory.Any(x => x.FullName.Equals(testCaseRun.FullName))) { var existingTestCaseHistory = existingTestCasesHistory.FirstOrDefault(x => x.FullName.Equals(testCaseRun.FullName)); // Creates the new test case history entry for the current run. if (existingTestCaseHistory != null) { var testCaseHistoryEntry = new TestCaseHistoryEntry { AvgDuration = testCaseRun.Duration, TestCaseHistoryId = existingTestCaseHistory.TestCaseHistoryId, }; _meissaRepository.Insert(testCaseHistoryEntry); // Get all previous runs for the test and add to the list the new entry. var allCurrentTestCaseHistoryEntries = testCaseHistoryEntries.Where(x => x.TestCaseHistoryId.Equals(existingTestCaseHistory.TestCaseHistoryId)).ToList(); allCurrentTestCaseHistoryEntries.Add(testCaseHistoryEntry); } // Calculate the new average duration for the current tests based on the new entry. double newAverageDurationTicks = testCaseHistoryEntries.Average(x => x.AvgDuration.Ticks); var newAverageDuration = new TimeSpan(Convert.ToInt64(newAverageDurationTicks)); // Update the test case history info. if (existingTestCaseHistory != null) { existingTestCaseHistory.AvgDuration = newAverageDuration; existingTestCaseHistory.LastUpdatedTime = DateTime.Now; _meissaRepository.Update(existingTestCaseHistory); } } else { // If no entries exist, we create the history test case and a new history entry. var testCaseHistoryDto = new TestCaseHistory() { FullName = testCaseRun.FullName, LastUpdatedTime = DateTime.Now, AvgDuration = testCaseRun.Duration, }; testCaseHistoryDto = await _meissaRepository.InsertWithSaveAsync(testCaseHistoryDto).ConfigureAwait(false); var testCaseHistoryEntry = new TestCaseHistoryEntry { AvgDuration = testCaseRun.Duration, TestCaseHistoryId = testCaseHistoryDto.TestCaseHistoryId, }; _meissaRepository.Insert(testCaseHistoryEntry); } } await _meissaRepository.SaveAsync().ConfigureAwait(false); } catch (Exception ex) { _logger.LogCritical($"Exception while updating test cases execution history. {ex.Message} {ex.InnerException?.StackTrace} {ex.InnerException?.Message}", ex); } return(Ok()); }