我在.net-core我的单元测试中遇到了Moq的问题。我使用nuget将Moq 4.7.63安装到这个项目中但是当我尝试在下面构建单元测试时,我收到以下错误。
错误CS0246类型或命名空间名称' Moq'无法找到(是 你错过了使用指令或程序集引用?)
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Mock<IPerson> p = new Mock<IPerson>();
Person p2 = new Person() { FirstName = "john", LastName = "doe" };
p.setup(x => x.FirstName).Returns("john");
Assert.AreEqual(p.FirstName, "john");
}
}
interface IPerson
{
string FirstName { get; set; }
string LastName { get; set; }
}
class Person : IPerson
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
上面的代码目前是此项目中的文件。我可以在我的依赖项下看到Moq安装但我似乎无法在我的代码中引用dll。如果有什么我想念的东西请告诉我。提前致谢
这是我的.csproj文件
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.7.63" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.11" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.11" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
答案 0 :(得分:3)
重启VS工作,感谢Dimitar Tsonev的修复