public ExceptionHandlerTests() { _context = new TestHttpContext(); _exceptionHandler = new ExceptionHandler( Mock.Of <ILogger <ApiExceptionHandler> >(), new IExceptionHandler[0]); }
public WhenHandlingDomainExceptionUsingCustomHandling() { _context = new TestHttpContext(); var myDomainException = new MyDomainException(); _customApiProblem = new ExtentedApiProblem { ProblemInstanceUri = "123piano:id", Title = "custom title", Detail = "expected detail text", HttpStatus = StatusCodes.Status412PreconditionFailed, ProblemTypeUri = "complex/problem", ExtraProperty = "Extra, extra, read al of it in this extra property." }; _secondCustomApiProblem = new ExtentedApiProblem { ProblemInstanceUri = "nonono:001", Title = "Empty", Detail = "details", HttpStatus = StatusCodes.Status205ResetContent, ProblemTypeUri = "type/unknown", ExtraProperty = "empty as well", }; var customDomainExceptionHandler = new Mock <IExceptionHandler>(); customDomainExceptionHandler .Setup(handler => handler.Handles(It.IsAny <DomainException>())) .Returns(true); customDomainExceptionHandler .Setup(handler => handler.GetApiProblemFor(It.IsAny <DomainException>())) .ReturnsAsync(() => _customApiProblem); customDomainExceptionHandler .SetupGet(handler => handler.HandledExceptionType) .Returns(typeof(MyDomainException)); var extraCustomDomainExceptionHandler = new Mock <IExceptionHandler>(); extraCustomDomainExceptionHandler .Setup(handler => handler.Handles(myDomainException)) .Returns(true); extraCustomDomainExceptionHandler .Setup(handler => handler.GetApiProblemFor(myDomainException)) .ReturnsAsync(() => _secondCustomApiProblem); var exceptionHandler = new ExceptionHandler( Mock.Of <ILogger <ApiExceptionHandler> >(), new[] { customDomainExceptionHandler.Object, extraCustomDomainExceptionHandler.Object }); exceptionHandler.HandleException(myDomainException, _context).GetAwaiter().GetResult(); }
public ExceptionHandlerTests() { _context = new TestHttpContext(); _exceptionHandler = new ExceptionHandler( Mock.Of <ILogger <ApiExceptionHandler> >(), new ApiProblemDetailsExceptionMapping[0], new IExceptionHandler[0], new ProblemDetailsHelper(new StartupConfigureOptions())); }