aspnet/MusicStore

Test query issue in StoreControllerTest

anpete opened this issue · 1 comments

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

Repro
Test:

public async Task Details_ReturnsAlbumDetail()

The query:

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

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.