public async void GetByIdAsync_ShouldReturnEmployee() { // Arrange var pets = new List <Pet> { new Pet { Id = 121, Name = "Dick", Type = "duck", OwnerId = 23, Owner = new Employee { Id = 134 } }, new Pet { Id = 212, Name = "Mat", Type = "cat", OwnerId = 48, Owner = new Employee { Id = 12 } } }; var options = new DbContextOptionsBuilder <AppContext>() .UseInMemoryDatabase(databaseName: "Pets2") .Options; using (var appContext = new AppContext(options)) { await appContext.Pets.AddRangeAsync(pets); await appContext.SaveChangesAsync(); } using (var appContext = new AppContext(options)) { var repo = new PetsRepository(appContext); // Act var result = await repo.GetByIdAsync(pets.First().Id); // Assert Assert.IsAssignableFrom <Pet>(result); Assert.Equal(pets.First().Id, result.Id); } }