We have a controller that derives from ControllerBase
with an action like this:
public async Task Get(int id)
{
try
{
In your tests, if you first create a ControllerContext, then ProblemDetails should be created as expected while executing controller code.
...
MyController controller;
[Setup]
public void Setup()
{
controller = new MyController();
controller.ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext
{
// add other mocks or fakes
}
};
}
...