public async Task GetAsync_Should_Return_DeserializedOutput() { var riotApiResponseHandlerMock = new Mock <IRiotApiResponseHandler>(); riotApiResponseHandlerMock.Setup(x => x.Execute(It.Is <HttpResponseMessage>(message => message == _mockHttpResponseMessage))) .Returns(Task.CompletedTask) .Verifiable(); using var httpClient = new RiotHttpClient(_mockRiotTokenResolver.Object, riotApiResponseHandlerMock.Object, new HttpClient(_mockHttpMessageHandler.Object)); var response = await httpClient.GetAsync <AccountResponse>(UriMock); response.Should().BeEquivalentTo(_mockAccountResponse); _mockHttpMessageHandler.VerifyAll(); _mockRiotTokenResolver.VerifyAll(); riotApiResponseHandlerMock.VerifyAll(); }
public async Task GetAsync_Should_Throw_On_ResponseHandlerError() { var apiResponseHandlerException = new Exception("it borked"); var riotApiResponseHandlerMock = new Mock <IRiotApiResponseHandler>(); riotApiResponseHandlerMock.Setup(x => x.Execute(It.Is <HttpResponseMessage>(message => message == _mockHttpResponseMessage))) .ThrowsAsync(apiResponseHandlerException) .Verifiable(); using var httpClient = new RiotHttpClient(_mockRiotTokenResolver.Object, riotApiResponseHandlerMock.Object, new HttpClient(_mockHttpMessageHandler.Object)); var responseException = await Assert.ThrowsAsync <RiotApiException>(async() => { await httpClient.GetAsync <AccountResponse>(UriMock); }); responseException.InnerException.Should().BeEquivalentTo(apiResponseHandlerException); responseException.Data["url"].Should().BeEquivalentTo(UriMock.ToString()); riotApiResponseHandlerMock.VerifyAll(); _mockRiotTokenResolver.VerifyAll(); riotApiResponseHandlerMock.VerifyAll(); }