Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invoking an async task on fluentassertion

probably a simple one, but cant get it to work;

i've changed the signature one on the methods to Task

On my unit tests i am using fluent assertions.

but cant get this to work:

        _catalogVehicleMapper
            .Invoking(m => m.MapToCatalogVehiclesAsync(searchResult, filtersInfo, request, default(CancellationToken)))
            .Should().Throw<ArgumentException>()
            .WithMessage("One of passed arguments has null value in mapping path and can not be mapped");

the MapToCatalogVehiclesAsync is the async method, but i need to await it, but awaiting and asyncing the invocation, doesnt seem to do it.. someone..?

like image 591
Roelant M Avatar asked Dec 08 '22 14:12

Roelant M


1 Answers

Although Fabio's answer is correct as well, you can also do this:

_catalogVehicleMapper
   .Awaiting(m => m.MapToCatalogVehiclesAsync(searchResult, filtersInfo, request, default(CancellationToken)))
   .Should().Throw<ArgumentException>()
   .WithMessage("One of passed arguments has null value in mapping path and can not be mapped");

And as a side-note, I suggest to always use wildcards in WithMessage. See point 10 from this blog post.

like image 94
Dennis Doomen Avatar answered Feb 12 '23 00:02

Dennis Doomen