我正在进行一项非常简单的单元测试。当我运行测试时,我得到异常无法加载文件或程序集'无法加载文件或程序集' System.Core,Version = 4.0.0.0 ..'在我的Project.json文件中添加" Microsoft.NETCore.Portable.Compatibility":" 1.0.1" 后,此错误开始出现。但它是必需的,否则我不能在单元测试中使用lambda Expression。
我的单元测试中没有编译时错误。我确定我的测试没有任何问题,因为project.json文件缺少某些东西。以下是我的考试。
Mock<RegistrationManager> manager = new Mock<RegistrationManager>();
Mock<RegistrationModel> model = new Mock<RegistrationModel>();
var value = manager.Setup(a => a.GetDataFieldValuesForModel(model.Object, CommandType.next)).ReturnsAsync(new RegistrationModel { hasError = false, FormId="123",LeadId="345" });
{
"version": "0.1.0-*",
"dependencies": {
"Moq": "4.5.22",
"xunit": "2.2.0-beta2-build3300",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"IntegraPay.Domain": {
"version": "1.0.0-*",
"target": "project"
},
"Integrapay.RegistrationApplication": {
"version": "",
"target": "project"
},
"Microsoft.NETCore.Portable.Compatibility": "1.0.1"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"net451"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
}
},
"testRunner": "xunit"
}
答案 0 :(得分:0)
有同样的问题。
通过几处改动解决了这个问题:
我的最终project.json看起来像:
{
"version": "1.0.0-*",
"dependencies": {
"NUnit": "3.5.0",
"dotnet-test-nunit": "3.4.0-beta-2",
"MyTestingProject": "1.0.0-*",
"Moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0"
},
"testRunner": "nunit",
"frameworks": {
"netcoreapp1.0": {
"imports": [
"netcoreapp1.0",
"dnxcore50"
],
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
}
}
}
}