huysentruitw / entity-framework-core-mock

Easy Mock wrapper for mocking EFCore5 DbContext and DbSet using Moq or NSubstitute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Appears to not work under EFCore 7

mlockett42 opened this issue · comments

Properties linked to related tables via foreign key don't seem to be populated

I have

            var query =
                from u in dbContext.Users
                where u.Id == userId
                select u.IsMaster || (
                    from ur in u.UserRoles
                    where
                        ur.Role.Name == "Developer"
                    select
                        1
                ).Any();

See (https://github.com/mlockett42/EntityFrameworkCoreMock.Fail/blob/master/EntityFrameworkCoreMock.Fail/DemonstrateEFCore7Error.cs#L72)

Which evaluate to false in spite of the face that user with Id == userId is linked to a UserRole which is linked to a Role named "Developer"

I have created this small project to demonstrate this error https://github.com/mlockett42/EntityFrameworkCoreMock.Fail

This works for us in EFCore 6 and 5 and the same version of EntityFrameworkCoreMock.Moq

Tried your provided solution - fails in EF Core 5, EF Core 6 and as well as in EF Core 7.
For as long as I am using this project, I don't remember it supporting auto mapping navigational properties. At least we always had that issue.
As well as updating property via navigation won't be reflected by a change in a table (for example, updating role name via user.Role.Name = "foo" (imagine it's a one-to-one relation for simplicity), you won't see that new name in Roles table).
At least these are two mains things that we always had, but came around them by setting those properties ourselves.