public async Task SendRequestGenericAsync_WithNullMessage_ThrowsArgumentNullException() { var service = new MockWatsonService("ausername", "apassword", new HttpClient(), new WatsonSettings()); var exception = await Record.ExceptionAsync(async () => await service.SendRequestAsync<bool>(null).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<ArgumentNullException>(exception); }
public async Task SendRequestAsync_ThrowWatsonException(string requestUrl, string handlerUrl, string responseContent, int statusCode, string exceptionMessage) { var httpStatusCode = (HttpStatusCode) Enum.ToObject(typeof (HttpStatusCode), statusCode); var requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUrl); var responseMessage = new HttpResponseMessage(httpStatusCode) {Content = new StringContent(responseContent)}; var httpClient = new HttpClient(new MockHttpMessageHandler(handlerUrl, responseMessage)); var service = new MockWatsonService("ausername", "apassword", httpClient, new WatsonSettings()); var exception = await Record.ExceptionAsync( async () => await service.SendRequestAsync(requestMessage).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<WatsonException>(exception); Assert.Equal(exceptionMessage, exception.Message); }