public void DeleteById_ItemDoesntExist_ThrowsException() { using (var context = new ApplicationDbContext(GetDbContextOptions("Delete_ItemDoesntExist_ThrowsException"))) { // Arrange var repo = new FruitRepository(context); // Assert Assert.ThrowsAny <Exception>(() => { // Act repo.DeleteById(123).Wait(); }); } }
public void DeleteById_ItemExists_DeletesItemSuccessfully() { using (var context = new ApplicationDbContext(GetDbContextOptions("DeleteById_ItemExists_DeletesItemSuccessfully"))) { // Arrange var repo = new FruitRepository(context); var item = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; repo.Add(item).Wait(); // Act repo.DeleteById(5).Wait(); // Assert var deletedItem = repo.GetById(5).Result; Assert.Null(deletedItem); } }