我正在使用单元测试(Nunit)测试 SendEmail:
// Arrange
var mockDbContext = new Mock<DbContext>();
IService service = new Service(mockDbContext.Object);
// Act
var result = service.SendEmail(string.Empty,1,1);
//Assert
Assert.That(result, Is.Not.Null);
Assert.That(result, Is.InstanceOf<bool>());
Assert.AreEqual(result, false);
public bool SendEmail(string emailAddress, int mId, int deadline)
{
try
{
dynamic email = new Email("CirculationEmail");
email.To = emailAddress;
email.MId = mId;
email.Deadline = deadline;
email.Send();
return true;
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
return false;
}
}
SendEmail 使用邮政。运行测试时出现以下错误。当我调试时,它甚至在我的 SendEmail 中的第一个调试点之前就抛出了错误。
System.IO.FileLoadException : Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
我将以下内容添加到 app.config 并搜索我的代码以查看它是否曾经引用 3.0.0.0,但它没有。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
我想知道MVC错误版本是否可能(以某种方式)掩盖了另一条错误消息?