我无法使用 Visual Studio 测试套件和 Moq 成功运行 MvcMailer 的单元测试。
我已经从 wiki 逐字复制了示例,但每次都会出现以下异常:
Test method MvcMailerTest.Tests.MailerTest.TestMethod1 threw exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: httpContext
代码如下:(使用VS单元测试框架-使用nUnit时出现与示例中完全相同的错误)
//Arrange: Moq out the PopulateBody method
var _userMailerMock = new Mock<UserMailer>();
_userMailerMock.Setup(mailer => mailer.PopulateBody(It.IsAny<MailMessage>(), "Welcome", null));
_userMailerMock.CallBase = true;
//Act
var mailMessage = _userMailerMock.Object.Welcome();
在 Welcome() 方法中的以下行失败(直接从 wiki 复制):
PopulateBody(mailMessage, viewName: "Welcome");
维基百科在这里:https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide
类似(几乎完全相同)的问题:MvcMailer:无法在使用 Url.Action 的 Razor 视图上完成 NUnit 测试
有人知道如何解决/解决这个问题吗?链接的问题说我需要模拟我已经完成的 PopulateBody 方法(根据维基)。