public void HttpClient_SetByConstructor1_IsValid() { var expectedUrl = "https://gateway.watsonplatform.net/document-conversion/api/"; var service = new DocumentConversionService("username", "password"); Assert.NotNull(service); Assert.NotNull(service.HttpClient); Assert.NotNull(service.HttpClient.BaseAddress); Assert.Equal(expectedUrl, service.ServiceUrl); Assert.Equal(expectedUrl, service.HttpClient.BaseAddress.ToString()); }
public async Task ConvertDocumentToTextAsync_NullFile_ThrowsArgumentNullException() { var service = new DocumentConversionService("username", "password", new WatsonSettings()); var exception = await Record.ExceptionAsync( async () => await service.ConvertDocumentToTextAsync(null, FileType.Xml).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<ArgumentNullException>(exception); }
public async Task ConvertDocumentToTextAsync() { var mockHttpMessageHandler = new MockHttpMessageHandler(); var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockDocumentConversionResponses.MockTextResponse) }; mockHttpMessageHandler.AddResponseMessage(ServiceUrl, mockResponse); var httpCLient = new HttpClient(mockHttpMessageHandler); var service = new DocumentConversionService("username", "password", httpCLient, new WatsonSettings()); var actual = await service.ConvertDocumentToTextAsync(new MemoryStream(), FileType.Html).ConfigureAwait(false); Assert.Equal(MockDocumentConversionResponses.MockTextResponse, actual); }