public void AddressesGatewayShouldThrowAnErrorWhenAPICallAuthenticationFails() //Forbidden - Gateway should tell that API key is incorrect - TODO: Integration test. { // arrange var statusCode = 403; var forbiddenResp = "{\"message\":\"Forbidden\"}"; var contextResponse = new AddressesAPIContextResponse(statusCode, forbiddenResp); _mockAddressesApiContext.Setup(c => c.GetAddressesRequest(It.IsAny <string>())).Returns(contextResponse); // act Action gatewayCall = () => _classUnderTest.GetPostcodeCoordinates(It.IsAny <string>()); // assert gatewayCall.Should().Throw <APICallNotAuthorizedException>().WithMessage($"A call to {"Addresses"} API was not authorized."); }
[TestCase(TestName = "Given Addresses API context's GetAddressesRequest method is called, When not found response is returned, Then the AddressesGateway throws APICallNotFoundException.")] // ideally would tell the url path or similar public void AddressesGatewayShouldThrowAnErrorWhenAPICallResultsInNotFound() { // arrange var statusCode = 404; var forbiddenResp = ""; var contextResponse = new AddressesAPIContextResponse(statusCode, forbiddenResp); _mockAddressesApiContext.Setup(c => c.GetAddressesRequest(It.IsAny <string>())).Returns(contextResponse); // act Action gatewayCall = () => _classUnderTest.GetPostcodeCoordinates(It.IsAny <string>()); // assert gatewayCall.Should().Throw <APICallNotFoundException>(); }