public async Task RegionLookupService_ReturnsEmptyStringAndLogsError_WhenHttpRequestFails() { // Arrange var config = CreateConfig(); var dummyLogger = A.Fake <ILogger <RegionLookupService> >(); var dummyClient = A.Fake <IHttpClient>(); var response = new HttpResponseMessage() { Content = new StringContent(""), StatusCode = HttpStatusCode.BadRequest }; A.CallTo(() => dummyClient.GetAsync(A <string> .That.Contains(_baseUrl))).Returns(response); var regionLookupService = new RegionLookupService(config, dummyClient, dummyLogger); // Act var postcode = "DUM MY"; var region = await regionLookupService.GetRegion(postcode); // Assert Assert.AreEqual(string.Empty, region); // A.CallTo(() => dummyLogger.LogError(A<string>.Ignored)).MustHaveHappened(); }
public async Task RegionLookupService_ReturnsCorrectRegion_GivenAPostcode() { // Arrange var config = CreateConfig(); var dummyLogger = A.Fake <ILogger <RegionLookupService> >(); var dummyClient = A.Fake <IHttpClient>(); var stubData = File.ReadAllText("Tests/Stubs/regionLookup.json"); var response = new HttpResponseMessage() { Content = new StringContent(stubData), StatusCode = HttpStatusCode.OK }; A.CallTo(() => dummyClient.GetAsync(A <string> .That.Contains(_baseUrl))).Returns(response); var regionLookupService = new RegionLookupService(config, dummyClient, dummyLogger); // Act var postcode = "DUM MY"; var region = await regionLookupService.GetRegion(postcode); // Assert var expectedRegion = JsonConvert.DeserializeObject <RegionLookupResult>(stubData).Result.Region; Assert.AreEqual(expectedRegion, region); }