3
我有一個WebAPI使用自定義ExceptionHandler
來處理所有異常。我怎麼能單元測試CustomExceptionHandler
。任何鉛會有所幫助如何使用MoQ和NUnit在WebAPI 2中爲ExceptionHandler編寫單元測試
public class CustomExceptionHandler : ExceptionHandler
{
public override void Handle(ExceptionHandlerContext context)
{
try
{
context.Result = new ResponseMessageResult(context.Request.CreateResponse(HttpStatusCode.InternalServerError, context.Exception));
}
catch (Exception)
{
base.Handle(context);
}
}
public override bool ShouldHandle(ExceptionHandlerContext context)
{
return true;
}
}