Do we already have this feature?
If no, I think this is necessery to make sure that Include statement is called or not in my repository or query.
The sample scenario:
public class Lesson {
public int Id {get; set;}
}
public class Student {
public int Id {get; set;}
public List<Lesson> Lessons { get; set; }
}
var student1 = new Student(){
Id = 1,
Lessons = new List<Lesson>(){
new Lesson(){
Id = 1,
}
}
}
var students = new List<Student>(){
student1
};
var dataSetMock = students.AsQueryable().BuildMockDbSet();
var dbContextMock = new Mock<IDbContextInterface>();
dbContextMock.SetupGet(e => e.Students)
.Returns(dataSetMock.Object);
var repository = new StudentsRepository(dbContextMock.Object);
var studentResult = repository.GetById("12312312");
studentResult.Lessons.Should().NotBeNull();
But this will causes studentResult == student1 returns false because we need to instansiate new object.
My suggestion for this, we can add new param in BuildMockDbSet
public static IQueryable<TEntity> BuildMock<TEntity>(this IQueryable<TEntity> data, bool loadNavigation= true) where TEntity : class {}
Thanks
:)
Do we already have this feature?
If no, I think this is necessery to make sure that
Includestatement is called or not in my repository or query.The sample scenario:
But this will causes
studentResult == student1returnsfalsebecause we need to instansiate new object.My suggestion for this, we can add new param in
BuildMockDbSetThanks
:)