public void CanceledBeforeResponse() { IWebClient client = new WebClientWrapper(); Uri uri = new Uri("http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso"); CancellationTokenSource cts = new CancellationTokenSource(100); Directory.CreateDirectory(TestOutputPath); string filePath = Path.Combine(TestOutputPath, "CanceledBeforeResponse.iso"); try { using (IWebResponseMessage response = client.GetAsync(uri, cts.Token).Result) { if (!response.IsSuccessStatusCode) { Assert.Fail($"Error getting response from {uri}: {response.ReasonPhrase}"); } Assert.Fail("Didn't throw exception"); } } catch (AggregateException ex) { if (!(ex.InnerException is OperationCanceledException)) { Assert.Fail("Wrong exception thrown."); } } catch (Exception) { Assert.Fail("Wrong exception thrown."); } cts.Dispose(); client.Dispose(); }
public async Task <PropertiesResponse> GetAsync() { var Url = new Uri(this._urlBase); var response = await WebClientWrapper.GetAsync <PropertiesResponse>(Url); return(response); }
public void WebClient_GetAsync_PageNotFound() { using (var mockClient = new MockWebClient()) using (var realClient = new WebClientWrapper()) { mockClient.Timeout = 5000; realClient.Timeout = 5000; realClient.ErrorHandling = ErrorHandling.ReturnEmptyContent; var testUrl = new Uri("https://bsaber.com/wp-jsoasdfn/bsabasdfer-api/songs/"); //WebUtils.Initialize(realClient); using (var realResponse = realClient.GetAsync(testUrl).Result) using (var mockResponse = mockClient.GetAsync(testUrl).Result) { var test = realResponse?.Content?.ReadAsStringAsync().Result; Assert.AreEqual(realResponse.IsSuccessStatusCode, mockResponse.IsSuccessStatusCode); Assert.AreEqual(realResponse.StatusCode, mockResponse.StatusCode); Assert.AreEqual(realResponse.Content?.ContentType, mockResponse.Content.ContentType); } } }