public void Update_ItemDoesntExist_ThrowsException() { using (var context = new ApplicationDbContext(GetDbContextOptions("Update_ItemDoesntExist_ThrowsException"))) { // Arrange var repo = new FruitRepository(context); var itemToUpdate = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; // Assert Assert.ThrowsAny <Exception>(() => { // Act repo.Update(itemToUpdate).Wait(); }); } }
public void Update_ItemExists_UpdatesItemSuccessfully() { using (var context = new ApplicationDbContext(GetDbContextOptions("Update_ItemExists_UpdatesItemSuccessfully"))) { // 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 item.Name = "Banana"; repo.Update(item).Wait(); // Assert var updatedItem = repo.GetById(5).Result; Assert.NotNull(updatedItem); Assert.Equal("Banana", updatedItem.Name); } }