我使用單元測試(NUnit的)測試SendEmail:單元測試 - 引用3.0.0.0 MVC,版本實際上4.0.0.0
// 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錯誤版本之一蒙上了(不知何故)?
你可以檢查,如果這可以幫助你 http://stackoverflow.com/questions/80287/how-can-i-build-a-dependency-tree-diagram-from-my-net-solution – ali
綁定重定向是否存在於您的測試程序集的app.config文件中,或僅用於您的Web應用程序項目? –