Skip to content

ActionResultExtensions are not working for Web API projects #15

Closed
@danielbecroft

Description

@danielbecroft

I'm not sure if it's something I'm doing, or a problem with a missing extension definition.

Our controller actions for an API project are defined as:

public async Task<ActionResult<IEnumerable<CustomerDto>>> Get()
{
    return Ok(await _mediator.Send(new GetCustomerQuery());
}

In the test:

var result = await sut.Get();

result.Should().BeOkObjectResult(); //

The code actually doesn't compile, as the Should() extension isn't detected properly. The extensions are defined as:

Should(this ActionResult actual);
Should(this IActionResult actual);

but the ActionResult is neither.

As a workaround, I've added an extension for Should(this IConvertToActionResult), and just call the .Convert() method.

Is there a better, or different approach here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions