Moq 库和 .NET Core 预览版 3.0

Moq library and .NET core preview 3.0

如何使 Moq 库与 .NET Core 预览版一起使用 3.x?有可能吗?

具体来说,当我启用 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'

编辑:问题的更新版本与Moq无关。您需要确保所有依赖项都已正确更新。 Microsoft.Extensions.Logging.Abstractions 未被 Moq 引用。

Edit2: 这里是 sample.

是的,这是可能的。 current version(截至目前的 4.12.0),支持 .NET-Standard 2.0。 .NET-Core 3.0 完全支持它,因此您可以像往常一样使用它。

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

您可以在 docs 中找到更多示例。