Using ReturnsAsync When Automocking in JustMock

16 views Asked by At

JustMock supports .ReturnsAsync() when arranging standard mocks, however I am unable to find a way to get this same behavior when Automocking with a MockingContainer<T>.

A solution I've found is to wrap the return value in Task.FromResult<T>(). This fulfills the expected Task<T> return type of the async function, however the syntax is a bit clunky.

service
    .Arrange<IRepository>(r => r.SomeAsyncMethod("input"))
    .Returns(Task.FromResult<ISomeModel>(resultModel));

Ideally, I would like to avoid building the Task<T> return values manually and just rely on .ReturnsAsync() to handle the conversion.

service
    .Arrange<IRepository>(r => r.SomeAsyncMethod("input"))
    .ReturnsAsync(resultModel);

It's possible the APIs just aren't there, but I want to ensure I'm not just missing some special syntax to get it working.

1

There are 1 answers

0
Drew Antonich On BEST ANSWER

I confirmed with Telerik staff that it's not currently possible to use .ReturnsAsync() for automocking.

The feature request has been created.