admin管理员组文章数量:1394099
I'm trying to mock and setup a XUnit test for my service when calling Azure EmailClient for both SendAsync
and Send
.
var EmailClientClientMock = new Mock<EmailClient>();
var emailSendOperationMock = new Mock<EmailSendOperation>();
EmailSendOperation emailSendOperation = new EmailSendOperation("random", EmailClientClientMock.Object);
var emailMessage = new Mock<EmailMessage>();
_mockEmailClient
.Setup(client => client.SendAsync(
It.Is<WaitUntil>(w => w == Azure.WaitUntil.Started),
It.IsAny<EmailMessage>()
))
.ReturnsAsync(mockResult);
But I'm having this issue - I don't know how to solve it:
An expression tree may not contain a call or invocation that uses optional arguments
Is wrapping this EmailClient
in an interface an option?
I'm trying to mock and setup a XUnit test for my service when calling Azure EmailClient for both SendAsync
and Send
.
var EmailClientClientMock = new Mock<EmailClient>();
var emailSendOperationMock = new Mock<EmailSendOperation>();
EmailSendOperation emailSendOperation = new EmailSendOperation("random", EmailClientClientMock.Object);
var emailMessage = new Mock<EmailMessage>();
_mockEmailClient
.Setup(client => client.SendAsync(
It.Is<WaitUntil>(w => w == Azure.WaitUntil.Started),
It.IsAny<EmailMessage>()
))
.ReturnsAsync(mockResult);
But I'm having this issue - I don't know how to solve it:
An expression tree may not contain a call or invocation that uses optional arguments
Is wrapping this EmailClient
in an interface an option?
- This question is similar to: An expression tree may not contain a call or invocation that uses optional arguments when mocking a function to return an object. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. – Ivan Petrov Commented Mar 15 at 0:47
- is the same doubt, no doubt - but for some reason i can't put it to work. plus. – dr.Xis Commented Mar 15 at 1:00
2 Answers
Reset to default 1It's strange error message, but what you are missing is last parameter for mocked method SendAsync
, which is CancellationToken
:
var EmailClientClientMock = new Mock<EmailClient>();
var emailSendOperationMock = new Mock<EmailSendOperation>();
var emailSendOperation = new EmailSendOperation("random", EmailClientClientMock.Object);
var emailMessage = new Mock<EmailMessage>();
EmailClientClientMock
.Setup(client => client.SendAsync(
It.Is<WaitUntil>(w => w == WaitUntil.Started),
It.IsAny<EmailMessage>(),
It.IsAny<CancellationToken>()
))
.ReturnsAsync(emailSendOperation);
it was actually very easy - and the answer was actually in the description - the optional part regard the cancelation token:
emailClientMock.Setup(c => c.SendAsync(WaitUntil.Started, It.IsAny<EmailMessage>(), It.IsAny<CancellationToken>()))
本文标签: cIssue with MoqSetup EmailClient for Azure Communication ServiceStack Overflow
版权声明:本文标题:c# - Issue with MoqSetup EmailClient for Azure Communication Service - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744627208a2616329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论