public async Task Given_IncorrectResponse_When_GetShakespheareTranslationAsync_IsCalled_Returns_DefaultValues() { //Arrange var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(FunTranslationsClientData.jsonData_Invalid) }; mockResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); mockHttpMessageHandler.Protected().Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(mockResponse); var client = new HttpClient(mockHttpMessageHandler.Object); client.BaseAddress = fixture.Create <Uri>(); mockHttpClientFactory.Setup(o => o.CreateClient(It.IsAny <string>())).Returns(client); //Act var translationsService = new TranslationsService(client); var response = await translationsService.GetShakespheareTranslationAsync("abcd"); //Assert Assert.NotNull(response); Assert.Null(response.Content); }
public async Task Given_Exception_When_GetShakespheareTranslationAsync_IsCalled_Returns_OriginalValue() { //Arrange var mockResponse = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("") }; mockResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); mockHttpMessageHandler.Protected().Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(mockResponse); var client = new HttpClient(mockHttpMessageHandler.Object); client.BaseAddress = fixture.Create <Uri>(); mockHttpClientFactory.Setup(o => o.CreateClient(It.IsAny <string>())).Returns(client); //Act var translationsService = new TranslationsService(client); var result = await translationsService.GetShakespheareTranslationAsync("abcd").ConfigureAwait(false); //Assert Assert.NotNull(result); Assert.Equal("abcd", result.Content.OriginalText); Assert.Null(result.Content.TranslatedText); }
public async Task Given_ValidInput_When_GetShakespheareTranslationAsync_IsCalled_Returns_ValidResponse() { //Arrange var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(FunTranslationsClientData.jsonData_Valid_Shakespeare) }; mockResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); mockHttpMessageHandler.Protected().Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(mockResponse); var client = new HttpClient(mockHttpMessageHandler.Object); client.BaseAddress = fixture.Create <Uri>(); mockHttpClientFactory.Setup(o => o.CreateClient(It.IsAny <string>())).Returns(client); //Act var translationsService = new TranslationsService(client); var response = await translationsService.GetShakespheareTranslationAsync("abcd"); //Assert Assert.NotNull(response); Assert.Equal("It can freely recombine its own cellular structure totransform into other life-forms.", response.Content.OriginalText); Assert.Equal("'t can freely recombine its own cellular structure totransform into other life-forms.", response.Content.TranslatedText); }
public async Task Given_InValidQueryParameterValue_When_GetShakespheareTranslationAsync_IsCalled_Returns_TranslatedShakespheareInfo() { //Arrange var httpClient = new HttpClient() { BaseAddress = new Uri(config["TranslationsService:BaseUri"]) }; var translationsService = new TranslationsService(httpClient); var inputText = "#$&$%#"; //Act var result = await translationsService.GetShakespheareTranslationAsync(inputText).ConfigureAwait(false); //Assert Assert.NotNull(result); }
public async Task Given_ValidRequest_When_GetShakespheareTranslationAsync_IsCalled_Returns_TranslatedShakespheareInfo() { //Arrange var httpClient = new HttpClient() { BaseAddress = new Uri(config["TranslationsService:BaseUri"]) }; var translationsService = new TranslationsService(httpClient); var inputText = "It can freely recombine its own cellular structure totransform into other life-forms."; //Act var result = await translationsService.GetShakespheareTranslationAsync(inputText).ConfigureAwait(false); //Assert Assert.NotNull(result); }