public void GetMetadataForArea_Exception_Is_Properly_Handled_And_Logged() { // arrange var mockedAreaService = new Mock <IAreaService>(); mockedAreaService.Setup(x => x.GetMetadataForArea( It.IsAny <double>(), It.IsAny <double>(), It.IsAny <Guid>())).Throws(new Exception("Joke")); var areaController = new AreaController(mockedAreaService.Object, _apiLogger.Object); // act var actionResult = areaController.GetAreaMetadata(-90, 90, Guid.NewGuid()); // assert _apiLogger.Verify(x => x.OnActionException(It.IsAny <HttpActionContext>(), It.IsAny <Exception>()), Times.Once); Assert.IsInstanceOfType(actionResult, typeof(ExceptionResult)); }
public void Client_Gets_AreaMetadata() { // arrange var mockedDataService = new Mock <IAreaService>(); mockedDataService.Setup(x => x.GetMetadataForArea( It.IsAny <double>(), It.IsAny <double>(), It.IsAny <Guid>())).Returns(new AreaMetadataResponseDto()); var areaController = new AreaController( mockedDataService.Object, _apiLogger.Object); // act var actionResult = areaController.GetAreaMetadata(-91, 91, Guid.NewGuid()); var contentResult = actionResult as BadRequestErrorMessageResult; // assert Assert.IsNotNull(contentResult); Assert.AreEqual(contentResult.Message, "Latitude and longitude values must be in the [-90, 90] range."); Assert.IsInstanceOfType(contentResult, typeof(BadRequestErrorMessageResult)); }