Exemple #1
0
        public void Ctor_ConfigurationIsNull_ThrowsInvalidOperationException()
        {
            var messageHandler = MessageHandlerBuilder.GetSuccessfulResponseMessageHandler(_exampleYodaJsonResponse);
            var client         = new HttpClient(messageHandler);

            Assert.ThrowsException <InvalidOperationException>(() => new PokeapiSpeciesReader(client, _httpClientConfiguration.Object));
        }
        public async Task Read_ClientThrowsException_ThrowsHttpRequestException()
        {
            SetupConfiguration();
            var client = new HttpClient(MessageHandlerBuilder.GetExceptionThrowingMessageHandler());
            var reader = new PokeapiSpeciesReader(client, _httpClientConfiguration.Object);

            await Assert.ThrowsExceptionAsync <HttpRequestException>(() => reader.Read("name"));
        }
        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);
        }
        public async Task Read_ClientReturnsSimplifiedMewtwoJson_CorrectName()
        {
            SetupConfiguration();
            var messageHandler = MessageHandlerBuilder.GetSuccessfulResponseMessageHandler(_simplifiedMewtwoResponseContent);
            var client         = new HttpClient(messageHandler);
            var reader         = new PokeapiSpeciesReader(client, _httpClientConfiguration.Object);

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

            Assert.AreEqual("mewtwo", pokemonSpecies.Name);
        }
        public async Task Read_ClientReturnsSimplifiedMewtwoJson_HasFlavorTextEntry(string flavorText, string languageName)
        {
            SetupConfiguration();
            var messageHandler = MessageHandlerBuilder.GetSuccessfulResponseMessageHandler(_simplifiedMewtwoResponseContent);
            var client         = new HttpClient(messageHandler);
            var reader         = new PokeapiSpeciesReader(client, _httpClientConfiguration.Object);

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

            Assert.IsTrue(pokemonSpecies.FlavorTextEntries.Any(fte => fte.FlavorText == flavorText && fte.Language.Name == languageName));
        }
Exemple #7
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));
        }
Exemple #8
0
        public async Task Read_YodaExampleSuccessfulResponse_HasCorrectTranslation()
        {
            SetupConfiguration();
            var messageHandler = MessageHandlerBuilder.GetSuccessfulResponseMessageHandler(_exampleYodaJsonResponse);
            var client         = new HttpClient(messageHandler);

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

            var response = await translationClient.Read(_exampleYodaTranslationRequest);

            Assert.AreEqual("Mr,  you gave.Tim a hearty meal,Made him die,  but unfortunately what he ate.", response.Contents.Translated);
        }