public async void GetAllOptionByProductIdAsync_ShouldGetOptions() { // Arrange //create in memory options var options = new DbContextOptionsBuilder <DataBaseContext>() .UseInMemoryDatabase(databaseName: "GetAllOptionByProductIdAsync_ShouldGetOptions") .Options; using (var context = new DataBaseContext(options)) { await context.AddRangeAsync(optionsList); await context.SaveChangesAsync(); Assert.Equal(2, await context.ProductOption.CountAsync()); } // Act using (var context = new DataBaseContext(options)) { var repo = new OptionRepository(context); var result = await repo.GetAllOptionByProductIdAsync(firstOption.ProductId); Assert.Equal(1, result.Count); Assert.Equal(firstOption.Id, result[0].Id); } }