I'm trying to check the HttpStatusCode from a call to the controller but I can't figure out how to convert my ActionResult<T> to HttpStatusCodeResult.
Method from the controller :
[Get]
public async Task<ActionResult<PagedResult<PersoDemandLiteResponse>>> GetDemandsByFilterAsync([FromQuery] DemandFilterRequest filter)
=> await this.GetAsync(() => DemandService.GetDemandByFilterAsync(filter), (sources) => sources);
Here is my test method (simplified) :
... mocking of the services ...
var controller = new DemandController(demandService, organizationService.Object, productService.Object, Mapper.Object);
var request = new DemandFilterRequest { OrganizationId = Guid.NewGuid() };
var result = await controller.GetDemandsByFilterAsync(request);
//I would like to do something like this
var action = result as HttpStatusCodeResult;
var badRequest = (int)HttpStatusCode.BadRequest;
Assert.Equal(badRequest, action.StatusCode);
But I get the following error :
Error CS0039 Cannot convert type 'Microsoft.AspNetCore.Mvc.ActionResult>' to 'System.Web.Mvc.HttpStatusCodeResult' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion.
Any idea on how to achieve this ?