public async Task Read_ClientReturnsInternalServerError_ThrowsHttpRequestException()
        {
            SetupConfiguration();
            var client = new HttpClient(MessageHandlerBuilder.GetResponseMessageHandler(HttpStatusCode.InternalServerError));
            var reader = new PokeapiSpeciesReader(client, _httpClientConfiguration.Object);

            await Assert.ThrowsExceptionAsync <HttpRequestException>(() => reader.Read("name"));
        }
        public async Task Read_ClientReturnsNotFound_ReturnsNull()
        {
            SetupConfiguration();
            var client = new HttpClient(MessageHandlerBuilder.GetResponseMessageHandler(HttpStatusCode.NotFound));
            var reader = new PokeapiSpeciesReader(client, _httpClientConfiguration.Object);

            var pokemonSpecies = await reader.Read("name");

            Assert.IsNull(pokemonSpecies);
        }
Beispiel #3
0
        public async Task Read_YodaExampleUnsuccessfulResponse_ThrowsHttpRequestException(HttpStatusCode httpStatusCode)
        {
            SetupConfiguration();
            var messageHandler = MessageHandlerBuilder.GetResponseMessageHandler(httpStatusCode);
            var client         = new HttpClient(messageHandler);

            _mockHttpClientFactory.Setup(cf => cf.CreateClient(It.IsAny <string>()))
            .Returns(client);
            var translationClient = new YodaTranslationClient(_mockHttpClientFactory.Object, _httpClientConfiguration.Object);

            await Assert.ThrowsExceptionAsync <HttpRequestException>(() => translationClient.Read(_exampleYodaTranslationRequest));
        }