我正在尝试测试传递给接口的参数是否正确:
MailMessage expectedMailMessage = new MailMessage();
var mailerMock = new Mock<IMailSender>();
mailerMock.Setup(m => m.Send(expectedMailMessage)).Verifiable();
Mailer mailer = new Mailer(mailerMock.Object);
mailer.Send(expectedMailMessage);
mailerMock.Verify(m => m.Send(expectedMailMessage), Times.Once());
邮件类:
public class Mailer : IMailer
{
private readonly IMailSender _mailSender;
public Mailer(IMailSender mailSender)
{
_mailSender = mailSender;
}
public void Send(MailMessage mailMessage)
{
_mailSender.Send(mailMessage);
}
}
但这仍然失败,问题是很难调试。我检查了是否生成了一些随机 Guid 或设置了日期,但我找不到任何东西。