Unable to cast object of type 'Microsoft.AspNetCore.Mvc.BadRequestObjectResult' to type

255 Views Asked by At

I'm working on a endpoint unit test for Controller and facing an error

System.InvalidCastException : Unable to cast object of type 'Microsoft.AspNetCore.Mvc.BadRequestObjectResult' to type 'CryptoAxus.Application.Features.Artist.GetOffersReceivedByArtist.Response.BadRequestGetOffersReceivedByArtistResponse'.

public class ArtistControllerTest { private readonly ArtistController _artistController;

public ArtistControllerTest()
{
    var mediator = new Mock<IMediator>();
    var logger = new Mock<ILogger<ArtistController>>();
    _artistController = new ArtistController(mediator.Object, logger.Object);
}  
[Fact]
public async Task When_Media_Type_Provided_Is_Incorrect_Expect_Bad_Request()
{
    // Arrange  // Act
    var response = await _artistController.GetOffersReceivedByArtist(234, new PaginationParameters(2, 3, "test"), "cryptoaxus@user");

    // Assert
    var value = (BadRequestGetOffersReceivedByArtistResponse)response;

    value.StatusCode.ShouldBe(HttpStatusCode.BadRequest);
    value.Result.ShouldBeNull();
    value.IsSuccessful.ShouldBe(false);
    value.Message.ShouldBe("Invalid media type provided");
    value.PaginationData.ShouldBeNull();
}

i have tried this

0

There are 0 best solutions below