daniel the man daniel the man - 18 days ago 8
C# Question

Type or namespace name Mock<> could not be found Entity Framework 6

I am trying to mock my

DbContext
for writing my unit tests.

I saw a tutorial, and by trying to do it like this:

[TestMethod]
public void MyFirstTest()
{
var mockSet = new Mock<DbSet<VMStored>>();
}


But I am getting the following error:


Type or namespace name Mock<> could not be found


I am using EF 6. I know this is something simple but I didn't find any answer online regarding this issue.

I don't know what assembly if needed I need to add or what package to install.

I did everything they said in the MSDN tutorial, including update my code in the
.Context.tt
file of the following function:

public string DbSet(EntitySet entitySet)
{
return string.Format(
CultureInfo.InvariantCulture,
"{0} virtual DbSet<{1}> {2} {{ get; set; }}",
Accessibility.ForReadOnlyProperty(entitySet),
_typeMapper.GetTypeName(entitySet.ElementType),
_code.Escape(entitySet));
}


Any ideas what I need to do?

Answer

Go to the Nuget Package Manager (right click project or solution in Solution Manager) and search for Moq. You're just missing the libraries.

Comments