public void AddBigFruits(IEnumerable <Fruit> fruits) { var bigFruits = fruits.Where(f => f.Size == FruitSizes.Big); foreach (var fruit in bigFruits) { _fruitRepository.Add(fruit); } }
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); } }
public void Add_SingleItem_ItemAddedSuccessfully() { using (var context = new ApplicationDbContext(GetDbContextOptions("Add_SingleItem_ItemAddedSuccessfully"))) { // Arrange var repo = new FruitRepository(context); var itemToAdd = new Fruit { Id = 5, Color = Color.Red, Name = "Apple", Price = 2.99m, Rating = 5, Description = "An apple" }; // Act repo.Add(itemToAdd).Wait(); // Assert var item = repo.GetById(5).Result; Assert.NotNull(item); Assert.Equal(5, item.Id); Assert.Equal("Apple", item.Name); } }
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); } }