3
votes

I'm trying to mock test with an asynchronous method but i don't know how to set up the moq test to allow it.

noSQLProvider.Setup(x => x.CreateDocumentAsync(It.IsIn<Uri>(), It.IsAny<object>())).Returns();

the error is telling me:

Usage: ResourceResponse x = await CreatDocumentAsync(...);

an expression tree may not contain a call or invocation that uses optional arguments.

1

1 Answers

4
votes

I'm guessing you're using this?

In which case the error message is telling you quite clearly that that method has optional parameters and you need to be explicit about them:

noSQLProvider.Setup(x => x.CreateDocumentAsync(It.IsIn<Uri>(),
                                               It.IsAny<object>(),
                                               It.IsAny<RequestOptions>(),
                                               It.IsAny<bool>())).Returns();

This is a limitation that isn't related to async.

NB - I'm not sure on how It.IsAny comparison behaves for nulls, so you might have to replace It.IsAny<RequestOptions>() with something that explicitly sets up that parameter to be null (which is the default).