public async Task ValidationFails() { _mediator.Setup(x => x.Send(It.IsAny <GetPostcodeCoordinatesRequest>(), It.IsAny <CancellationToken>())).Throws <Exception>(); var req = CreateInvalidRequest(); GetPostcodeCoordinates getPostcodeCoordinates = new GetPostcodeCoordinates(_mediator.Object, _loggerWrapper.Object); IActionResult result = await getPostcodeCoordinates.Run(req, CancellationToken.None); ObjectResult objectResult = result as ObjectResult; Assert.IsNotNull(objectResult); ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode> deserialisedResponse = objectResult.Value as ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode>; Assert.IsNotNull(deserialisedResponse); Assert.AreEqual(422, objectResult.StatusCode);; Assert.IsFalse(deserialisedResponse.HasContent); Assert.IsFalse(deserialisedResponse.IsSuccessful); Assert.AreEqual(1, deserialisedResponse.Errors.Count()); Assert.AreEqual(AddressServiceErrorCode.ValidationError, deserialisedResponse.Errors[0].ErrorCode); _mediator.Verify(x => x.Send(It.IsAny <GetPostcodeCoordinatesRequest>(), It.IsAny <CancellationToken>()), Times.Never); }
public async Task ErrorThrown() { _mediator.Setup(x => x.Send(It.IsAny <GetPostcodeCoordinatesRequest>(), It.IsAny <CancellationToken>())).Throws <Exception>(); var req = CreateRequest(); GetPostcodeCoordinates getPostcodeCoordinates = new GetPostcodeCoordinates(_mediator.Object, _loggerWrapper.Object); IActionResult result = await getPostcodeCoordinates.Run(req, CancellationToken.None); ObjectResult objectResult = result as ObjectResult; Assert.IsNotNull(objectResult); ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode> deserialisedResponse = objectResult.Value as ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode>; Assert.IsNotNull(deserialisedResponse); Assert.AreEqual(500, objectResult.StatusCode);; Assert.IsFalse(deserialisedResponse.HasContent); Assert.IsFalse(deserialisedResponse.IsSuccessful); Assert.AreEqual(1, deserialisedResponse.Errors.Count()); Assert.AreEqual(AddressServiceErrorCode.UnhandledError, deserialisedResponse.Errors[0].ErrorCode); _mediator.Verify(x => x.Send(It.IsAny <GetPostcodeCoordinatesRequest>(), It.IsAny <CancellationToken>())); _loggerWrapper.Verify(x => x.LogErrorAndNotifyNewRelic(It.Is <string>(y => y.Contains("Unhandled error")), It.IsAny <Exception>())); }
public async Task HappyPath() { var req = CreateRequest(); GetPostcodeCoordinates getPostcodeCoordinates = new GetPostcodeCoordinates(_mediator.Object, _loggerWrapper.Object); IActionResult result = await getPostcodeCoordinates.Run(req, CancellationToken.None); OkObjectResult objectResult = result as OkObjectResult; Assert.IsNotNull(objectResult); Assert.AreEqual(200, objectResult.StatusCode); ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode> deserialisedResponse = objectResult.Value as ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode>; Assert.IsNotNull(deserialisedResponse); Assert.IsTrue(deserialisedResponse.HasContent); Assert.IsTrue(deserialisedResponse.IsSuccessful); Assert.AreEqual(0, deserialisedResponse.Errors.Count()); Assert.AreEqual(1, deserialisedResponse.Content.PostcodeCoordinates.Count()); _mediator.Verify(x => x.Send(It.IsAny <GetPostcodeCoordinatesRequest>(), It.IsAny <CancellationToken>())); }