protected void SendTestResults(TestRunBase testRun) { try { TestContext.Progress.WriteLine("Test run completed. Trying to send results..."); var result = _resultSender.SendAsync(testRun).Result; if (result.Success) { TestContext.Progress.WriteLine("Results succesfully sent."); } else { TestContext.Progress.WriteLine("Sending results failed."); TestContext.Progress.WriteLine(result.Message); } } catch (AggregateException ex) { TestContext.Error.WriteLine("Something went wrong while sending the test results."); foreach (var innerException in ex.InnerExceptions) { TestContext.Error.WriteLine($"Exception: {innerException}"); } } catch (Exception ex) { TestContext.Error.WriteLine("Something went wrong while sending the test results."); TestContext.Error.WriteLine($"Exception: {ex}"); } }
public async Task <Result> SendAsync(TestRunBase testRun) { await RefreshAccessToken(); var webApiTestRunsUrl = "api/testruns"; switch (testRun) { case ExerciseTestRun _: webApiTestRunsUrl += "/forexercise"; break; case ProjectComponentTestRun _: webApiTestRunsUrl += "/forproject"; break; } var response = await _httpHandler.PostAsJsonAsync(webApiTestRunsUrl, testRun); if (response.StatusCode == HttpStatusCode.Unauthorized) { //retry with token retrieved remotely await RefreshAccessToken(allowCachedToken : false); response = await _httpHandler.PostAsJsonAsync(webApiTestRunsUrl, testRun); } var result = new Result(response.IsSuccessStatusCode); if (!result.Success) { result.Message = await response.Content.ReadAsStringAsync(); } return(result); }