public void InitSuccessfullyWithoutHttpClient() { // Create a provider using a null client SimpleHttpProvider testSimpleHttpProvider = new SimpleHttpProvider(null, this.serializer.Object); // Assert that the httpclient is set (from the factory) Assert.NotNull(testSimpleHttpProvider.httpClient); }
public SimpleHttpProviderTests() { this.testHttpMessageHandler = new TestHttpMessageHandler(); this.authProvider = new MockAuthenticationProvider(); this.serializer = new MockSerializer(); var defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider.Object); var httpClient = GraphClientFactory.Create(handlers: defaultHandlers, finalHandler: testHttpMessageHandler); this.simpleHttpProvider = new SimpleHttpProvider(httpClient, this.serializer.Object); }
public async Task SendAsync_ThrowsClientTimeoutException() { using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://localhost")) { this.simpleHttpProvider.Dispose(); var clientException = new TaskCanceledException(); var defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider.Object); var httpClient = GraphClientFactory.Create(handlers: defaultHandlers, finalHandler: new ExceptionHttpMessageHandler(clientException)); this.simpleHttpProvider = new SimpleHttpProvider(httpClient, this.serializer.Object); ServiceException exception = await Assert.ThrowsAsync <ServiceException>(async() => await this.simpleHttpProvider.SendAsync( httpRequestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None)); Assert.True(exception.IsMatch(ErrorConstants.Codes.Timeout)); Assert.Equal(ErrorConstants.Messages.RequestTimedOut, exception.Error.Message); Assert.Equal(clientException, exception.InnerException); } }
public async Task InitSuccessfullyWithUsedHttpClient() { // Create a httpClient var defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider.Object); using (HttpClient httpClient = GraphClientFactory.Create(handlers: defaultHandlers, finalHandler: testHttpMessageHandler)) using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://localhost")) using (var httpResponseMessage = new HttpResponseMessage()) { this.testHttpMessageHandler.AddResponseMapping(httpRequestMessage.RequestUri.ToString(), httpResponseMessage); // use the httpClient to send something out await httpClient.SendAsync(httpRequestMessage); // Create a provider using the same client SimpleHttpProvider testSimpleHttpProvider = new SimpleHttpProvider(httpClient, this.serializer.Object); // Assert that using the used client throws no errors on initialization Assert.NotNull(testSimpleHttpProvider.Serializer); Assert.Equal(httpClient.Timeout, simpleHttpProvider.OverallTimeout); } }