简体   繁体   English

Moq库和.NET Core预览3.0

[英]Moq library and .NET core preview 3.0

How can I make the Moq library work with .NET core preview 3.x ? 如何使Moq库与.NET Core Preview 3.x一起使用? Is it possible at all? 有可能吗?

Specifically, when I enable Moq there is a conflict with the logging library: 具体来说,当我启用Moq时,就会与日志记录库发生冲突:

MyProjectTest.cs(25, 45): [CS1705] :

Assembly 'MyProject' with identity 'MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 
uses 'Microsoft.Extensions.Logging.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' 

which has a higher version than referenced assembly 

'Microsoft.Extensions.Logging.Abstractions' with identity
 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Edit: The updated version of the question has nothing to do with Moq . 编辑:问题的更新版本与Moq无关。 You need to make sure that all dependencies are updated properly. 您需要确保所有依赖项都已正确更新。 Microsoft.Extensions.Logging.Abstractions is not referenced by Moq . Moq未引用Microsoft.Extensions.Logging.Abstractions

Edit2: Here a sample . 编辑2:这是一个示例

Yes, it is possible. 对的,这是可能的。 The current version (as of now 4.12.0), supports .NET-Standard 2.0. 当前版本 (截止到4.12.0)支持.NET-Standard 2.0。 That is fully supported by .NET-Core 3.0 so you would use it like you always did. .NET-Core 3.0完全支持该功能,因此您将像往常一样使用它。

var mock = new Mock<ISomeService>(MockBehavior.Loose);
mock.Setup(someService => someService.IsValidString(it.IsAny<string>)
   .Returns(true);

You can find more samples in the docs . 您可以在docs中找到更多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在.NET 4.8中引用.NET Core 3.0库? - Reference a .NET Core 3.0 library in .NET 4.8? 创建 .net 核心 3.0 class 库问题 - creating a .net core 3.0 class library problems 在 ASP.NET Core 3.0 Preview 5 或更高版本中配置 AutoFac - Configure AutoFac in ASP.NET Core 3.0 Preview 5 or higher 从预览版更新到 .net 核心 3.0 版本后出现异常 - Exception after updating from preview to .net core 3.0 release 如何在 .Net 核心中 Moq DataLakeServiceClient - How to Moq DataLakeServiceClient in .Net core Azure Devops上的Net Core 3.0 SDK Preview 9的Visual Studio Build失败 - Visual Studio Build Fails for Net Core 3.0 SDK Preview 9 on Azure Devops 如何在ASP.NET Core 3.0 Preview 5中将声明映射选项传递给IdentityServerJwt? - How to pass claims mapping options to IdentityServerJwt in ASP.NET Core 3.0 Preview 5? 使用 ASP.Net Core SDK 3.0 preview8(Blazor 框架)上传图像 - Uploading image using ASP.Net Core SDK 3.0 preview8 (Blazor framework) 如何使用ASP.NET Core Identity v Preview 3.0创建自定义用户和角色? - How i can create custom user and role with ASP.NET Core identity v preview 3.0? 在.NET Core 3.0 Preview9项目中使用System.Windows.Forms类 - Using System.Windows.Forms classes in a .net core 3.0 preview9 project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM