I am trying to mock my DbContext
for writing my unit tests.
I saw a tutorial, and tried to do it like the following:
[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?
Solution 1 That may be it's in a different project in the current solution, in a external DLL, or just in a different namespace in another file in the current project. Start by hovering the mouse over the error, and open the drop down that appears. If it has an "include" option, click that, and it should fix it.
Mocking is a way to encapsulate your unit tests. If you want to test a service method you are not interested if the repository is working. For this you will write repository tests. Therefore you mock the repository call and tell which result should be returned to test your method in all possible situation.
Go to the Nuget Package Manager (right click project or solution in Solution Manager) and search for Moq. You're just missing the libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With