public async Task SendRequestAsync_WithUnauthorizedErrorMessage__ThrowsImgurException() { var mockUrl = "http://example.org/test"; var mockResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized) { Content = new StringContent(MockErrors.ImgurClientError) }; var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)); var endpoint = new MockEndpoint(new ImgurClient("123", "1234"), httpClient); var request = new HttpRequestMessage(HttpMethod.Get, "http://example.org/test"); var exception = await Record.ExceptionAsync( async () => await endpoint.SendRequestAsync<Image>(request).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<ImgurException>(exception); }
public async Task SendRequestAsync_WithMessage_Equal() { var constructorObjects = new object[2]; constructorObjects[0] = new ImgurClient("123", "1234"); var mockUrl = "http://example.org/test"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockImageEndpointResponses.Imgur.GetImage) }; var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)); var endpoint = new MockEndpoint(new ImgurClient("123", "1234"), httpClient); var request = new HttpRequestMessage(HttpMethod.Get, "http://example.org/test"); var image = await endpoint.SendRequestAsync<Image>(request).ConfigureAwait(false); Assert.NotNull(image); }
public async Task SendRequestAsync_WithMessageNull_ThrowsArgumentNullException() { var httpClient = new HttpClient(new MockHttpMessageHandler()); var endpoint = new MockEndpoint(new ImgurClient("123", "1234"), httpClient); var exception = await Record.ExceptionAsync( async () => await endpoint.SendRequestAsync<Image>(null).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<ArgumentNullException>(exception); }
public async Task SendRequestAsync_WithInvalidUrl__ThrowsImgurException() { var mockUrl = "http://example.org/test"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("hello world") }; var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)); var endpoint = new MockEndpoint(new ImgurClient("123", "1234"), httpClient); //Query a url we know doesn't exist in the fake handler var request = new HttpRequestMessage(HttpMethod.Get, "http://example.org/test2"); var exception = await Record.ExceptionAsync( async () => await endpoint.SendRequestAsync<Image>(request).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<ImgurException>(exception); }