public async void Reviews_GetAllAdminAsync_Test() { var options = new DbContextOptionsBuilder <DreamFoodDeliveryContext>() .UseInMemoryDatabase(databaseName: "Reviews_GetAllAdminAsync_Test") .Options; // Run the test against one instance of the context using (var context = new DreamFoodDeliveryContext(options)) { context.AddRange(_reviews); await context.SaveChangesAsync(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DreamFoodDeliveryContext(options)) { var service = new ReviewService(_mapper, context); var reviewInBase = await context.Reviews.AsNoTracking().ToListAsync(); var result = await service.GetAllAdminAsync(); foreach (var item in reviewInBase) { var itemFromResult = result.Data.Where(_ => _.Headline.Equals(item.Headline, StringComparison.OrdinalIgnoreCase)).Select(_ => _).FirstOrDefault(); itemFromResult.Should().NotBeNull(); } } }