public async void DeleteArticleByIdAsync_ShouldThrowArgumentNullExceptionWithInvalidArticleId() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "DeleteArticleByIdAsync_ShouldThrowArgumentNullExceptionWithInvalidArticleId") .Options; TechAndToolsDbContext context = new TechAndToolsDbContext(options); IArticleService articleService = new ArticleService(context); await this.SeedData(context); int invalidArticleId = 1111; await Assert.ThrowsAsync <ArgumentNullException>(() => articleService.DeleteArticleByIdAsync(invalidArticleId)); }
public async void DeleteArticleByIdAsync_ShouldDeleteArticleFromDatabaseById() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "DeleteArticleByIdAsync_ShouldDeleteArticleFromDatabaseById") .Options; TechAndToolsDbContext context = new TechAndToolsDbContext(options); IArticleService articleService = new ArticleService(context); await this.SeedData(context); int articleId = 1; int expectedCount = context.Articles.ToList().Count - 1; bool actualResult = await articleService.DeleteArticleByIdAsync(articleId); int actualCount = context.Articles.ToList().Count; Assert.True(actualResult); Assert.Equal(expectedCount, actualCount); }