-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to not load the navigation property #45
Comments
Hi @leopripos, thanks you for the feedback. I would really like to help you. What happening in |
Closing the issue, since there is not enough details to reproduce it |
Sorry @romantitov for the slow response. My bad. The issue is "How do I make sure (test) that the public Student GetById(string id)
{
return _dbContext.Students
.Include(e => e.Lessons)
.Where(e => e.Id == id)
.FirstOrDefault();
} In the test code above, public Student GetById(string id)
{
return _dbContext.Students
.Where(e => e.Id == id)
.FirstOrDefault();
} That's because, it returns the |
@leopripos I think the problem is that MockQueryable creates an in-memory queryable (Linq to Objects), but If it were possible, it would be awesome... I just ran into an issue with a filtered include (EF Core 5), and I'm now realizing that MockQueryable can't do anything about it. |
@leopripos, thank you for more detailed explanation. I agree, that would be a very useful feature. I even did some research and I think technically it is possible (with some changes) to see whether an I usually work with the project in my free time and now I'm quite busy with my commercial projects for now. I'll keep the issue opened and who knows, maybe one day me or someone else will add the feature to the project. But I cannot promise that it will be soon. |
@romantitov assuming you're able to detect the call to 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();
Both approaches have issues:
|
@thomaslevesque I see it a bit different. I think that it's not a good idea to create a new unexpected instance, but I would like to make it possible to verify that expected 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();
.....
dataSetMock.VerifyInclude(x => x.Lessons ); |
Ah, I see |
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:
But this will causes
studentResult == student1
returnsfalse
because we need to instansiate new object.My suggestion for this, we can add new param in
BuildMockDbSet
Thanks
:)
The text was updated successfully, but these errors were encountered: