[英]How to mock this EmailCreation for unit Test in c#
Hi I´m trying to test a class of my project that generate a SendResponse with an Email template您好,我正在尝试测试我的项目的 class,它使用 Email 模板生成 SendResponse
this is my code这是我的代码
await Email.Create()
.To(request.Parcel.CustomerEmail)
.Subject(emailSubject)
.UsingTemplateFromEmbedded(emailTemplate, new ParcelReceivedEmailModel()
{
Parcel = request.Parcel,
Shop = shopInfo
}, GetType().Assembly)
.SendAsync(cancellationToken);
in the xunit test class i´m mocking IFluentEmailFactory to test that, this is my mock code:在 xunit 测试 class 我是 mocking IFluentEmailFactory 来测试它,这是我的模拟代码:
_mockFluentEmailFactory.Setup(x => x.Create()
.To(It.IsAny<string>())
.Subject(It.IsAny<string>())
.UsingTemplateFromEmbedded(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<string>(),It.IsAny<string>())
.SendAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(fakeSendResponse);
but i get allways a nullException and I don´t know why, can someone help me?但我总是得到一个 nullException,我不知道为什么,有人可以帮助我吗? im new doing test and it seems no to be so difficult
我是新来的测试,似乎没有那么难
I search information in xunit我在xunit中搜索资料
Solved:解决了:
.UsingTemplateFromEmbedded(It.IsAny<string>(), It.IsAny<ParcelReceivedEmailModel>(), It.IsAny<Assembly>(), It.IsAny<bool>())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.