我无法使用visual studio测试套件和Moq成功运行MvcMailer的单元测试。 我从一个字维基字复制的例子,但每次出现以下情况例外:MvcMailer单元测试:System.ArgumentNullException httpContext不能为空
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();
上在欢迎()方法将下面的行失败(复制直出维基):
PopulateBody(mailMessage, viewName: "Welcome");
维基是在这里:https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide
类似的(几乎完全一样)问:MvcMailer: Can't complete NUnit tests on Razor Views which use Url.Action
任何人都知道如何解决/解决这个问题?链接的问题说,我需要嘲笑我所做的PopulateBody方法(按照wiki)。
已向MVC Mailer团队报告此问题(https://github.com/smsohan/MvcMailer/issues/20),但未经解决就关闭了。有没有人有解决方法/修复? – jhappoldt 2011-08-25 18:26:47
@Josh,不幸的是,我仍然没有找到解决方法或解决方法。猜猜这个bug是在MVC邮件发送者手中的... – woggles 2011-08-25 19:10:52
解决方法是将您的代码更改为:'PopulateBody(mailMessage,“Welcome”,null);'这会工作,因为您有一个模拟设置PopulateBody的超载,而不是它的2参数版本。 – 2012-02-28 09:50:30