aspnet / MusicStore

[Archived] MusicStore test application that uses ASP.NET/EF Core. Project moved to https://github.com/aspnet/AspNetCore
1.3k stars 878 forks source link

Test query issue in StoreControllerTest #742

Closed anpete closed 7 years ago

anpete commented 7 years ago

Queries that used to return an entity with InMemory store now return null.

Repro Test: https://github.com/aspnet/MusicStore/blob/dc60a2e9c5e89d4f4324bb82e5c1af17f7d4490b/test/MusicStore.Test/StoreControllerTest.cs#L108

The query: https://github.com/aspnet/MusicStore/blob/dc60a2e9c5e89d4f4324bb82e5c1af17f7d4490b/samples/MusicStore/Controllers/StoreController.cs#L59-L63

album = await DbContext.Albums
               .Where(a => a.AlbumId == id)
               .Include(a => a.Artist)
               .Include(a => a.Genre)
               .FirstOrDefaultAsync();

When the .Include extensions are removed from the query, it returns an entity as expected.

Reason: Artist should never be null here - It is configured in the model as Required by convention because Album.ArtistId is not nullable. Either configure the relationship to be Optional, or ensure that the test albums have artists assigned.

kichalla commented 7 years ago

4039126e16fa13a464818d065aa4b381fb749e4f