I started writing tests for a (webapi) application in .net core using ef core. The repositories I want to test look like this:
public class MyRepository : IMyRepository
{
private readonly IDbContext Db;
public MyReporitory(IDbContext db)
{
Db = db;
}
/// Methods to access the Database
public List<MyType> Get() {
return Db.Set<Type>();
}
In my test I now try to mock the DBContext:
var dbContextMock = new Mock<IDBContext>();
var classToBeTested = new MyRepository(dbContextMock)
var result = classToBeTested.Get() (or any other method in my repository);
Assert.That(result, Is.TypeOf<MyType>)
When I run the test I get a null exception since the returned result is null (and I didnt tell the mock how to return data?) How would I add data to the mocked DbContext so the Get() can get it?