Reputation: 6262
Using .net core xunit and moq.
While writing my test case, I am getting the error"
An expression tree may not contain a call or invocation that uses optional arguments
The error is on line:
var moqDb = new Mock<IDynamoDbClientInitialization>();
moqDb
.Setup(_ => _.GetContext().ScanAsync<MyModel>
(It.IsAny<List<ScanCondition>>(), AWSHelperMethods.GetDynamoDbOperationConfig(dynamoDbTable)).GetRemainingAsync())
.ReturnsAsync(data);
For full code for this one can refer the post at: .Net core testing with Xunit
Could anyone help resolving my error here.
This post is for resolving the error I am getting, not asking for writing the unit case
Upvotes: 2
Views: 5050
Reputation: 1327
moqDb is intance of Mock:
moqDb
.Setup(_ => _.GetContext().ScanAsync<MyModel>
In this part of the code you trying to "call" a method ScanAsync on not already set up GetContext(). To solve this you have to Setup return value for GetContext() before you tried to Setup ScanAsync()
Upvotes: 1