public async Task InsertWalletAsync_PreviousWalletEntries_NewWalletEntry() { //// Arrange // Setup In-Memory Database at desired state DbContextOptions <WalletContext> dbContextOptions = new DbContextOptionsBuilder <WalletContext>() .UseInMemoryDatabase(databaseName: "InsertWalletAsync_PreviousWalletEntries_NewWalletEntry") .Options; WalletEntry[] previousEntries = new[] { new WalletEntry { Id = Guid.NewGuid().ToString(), EventTime = DateTime.UtcNow, Amount = 10, BalanceBefore = 0 }, new WalletEntry { Id = Guid.NewGuid().ToString(), EventTime = DateTime.UtcNow.AddTicks(1), Amount = 10, BalanceBefore = 0 } }; using (WalletContext context = new WalletContext(dbContextOptions)) { await context.AddRangeAsync(previousEntries); context.SaveChanges(); } // Initialize Entry WalletEntry expectedNewEntry = new WalletEntry { Id = Guid.NewGuid().ToString(), EventTime = DateTime.UtcNow, Amount = 10, BalanceBefore = 0 }; //// Act using (WalletContext context = new WalletContext(dbContextOptions)) { IWalletRepository walletRepository = new WalletRepository(context); await walletRepository.InsertWalletEntryAsync(expectedNewEntry); } //// Assert DbSet <WalletEntry> actualWalletEntries; using (WalletContext context = new WalletContext(dbContextOptions)) { actualWalletEntries = context.Transactions; Assert.Collection(actualWalletEntries, walletEntry => walletEntry.ShouldCompare(previousEntries[0]), walletEntry => walletEntry.ShouldCompare(previousEntries[1]), walletEntry => walletEntry.ShouldCompare(expectedNewEntry)); } }