public async Task DeleteMessageAsync_MessageIsDeleted_WhenMessageIsFound() { using (var db = new PellokITHomeContext(Utilities.TestDbContextOptions())) { #region snippet1 // Arrange var seedMessages = PellokITHomeContext.GetSeedingArticles(); await db.AddRangeAsync(seedMessages); await db.SaveChangesAsync(); var recId = 1; var expectedMessages = seedMessages.Where(message => message.ID != recId).ToList(); #endregion #region snippet2 // Act await db.DeleteArticleAsync(recId); #endregion #region snippet3 // Assert var actualMessages = await db.Articles.AsNoTracking().ToListAsync(); Assert.Equal( expectedMessages.OrderBy(m => m.ID).Select(m => m.Title), actualMessages.OrderBy(m => m.ID).Select(m => m.Title)); #endregion } }
public async Task DeleteMessageAsync_NoMessageIsDeleted_WhenMessageIsNotFound() { using (var db = new PellokITHomeContext(Utilities.TestDbContextOptions())) { // Arrange var expectedMessages = PellokITHomeContext.GetSeedingArticles(); await db.AddRangeAsync(expectedMessages); await db.SaveChangesAsync(); var recId = 4; // Act try { await db.DeleteArticleAsync(recId); } catch { // recId doesn't exist } // Assert var actualMessages = await db.Articles.AsNoTracking().ToListAsync(); Assert.Equal( expectedMessages.OrderBy(m => m.ID).Select(m => m.Title), actualMessages.OrderBy(m => m.ID).Select(m => m.Title)); } }
public async Task DeleteAllMessagesAsync_MessagesAreDeleted() { using (var db = new PellokITHomeContext(Utilities.TestDbContextOptions())) { // Arrange var seedMessages = PellokITHomeContext.GetSeedingArticles(); await db.AddRangeAsync(seedMessages); await db.SaveChangesAsync(); // Act await db.DeleteAllArticlesAsync(); // Assert Assert.Empty(await db.Articles.AsNoTracking().ToListAsync()); } }
public async Task GetMessagesAsync_MessagesAreReturned() { using (var db = new PellokITHomeContext(Utilities.TestDbContextOptions())) { // Arrange var expectedMessages = PellokITHomeContext.GetSeedingArticles(); await db.AddRangeAsync(expectedMessages); await db.SaveChangesAsync(); // Act var result = await db.GetArticlesAsync(); // Assert var actualMessages = Assert.IsAssignableFrom <List <Article> >(result); Assert.Equal( expectedMessages.OrderBy(m => m.ID).Select(m => m.Title), actualMessages.OrderBy(m => m.ID).Select(m => m.Title)); } }