While trying to MOCK AWS Cognito Signup Method using Moq
C#
public async void Signup(UserTO user)
{
var req = new SignUpRequest()
{
};
_cognito.Setup(m =>
m.SignUpAsync(It.IsAny<SignUpRequest>())) // LOE
.ReturnsAsync(() =>
new SignUpResponse()
{
});
}
But at the #LOE, getting the below error
Error CS0854 An expression tree may not contain a call or invocation that uses optional arguments
If I press f12 to get the definition of the SignUpAsync(), it looks as
Task<SignUpResponse> SignUpAsync(SignUpRequest request, CancellationToken cancellationToken = default(CancellationToken));
What's causing this error & how to get rid of this?
Thanks!
The mock expects the entire member definition to be configured/setup
Expect the options parameter using It.IsAny<CancellationToken>()
public async Task Signup(UserTO user) {
var req = new SignUpRequest() {
};
_cognito.Setup(m =>
m.SignUpAsync(It.IsAny<SignUpRequest>(), It.IsAny<CancellationToken>())
)
.ReturnsAsync(() => new SignUpResponse());
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With