public void GetByIdWithToppings_ShouldReturnPizzaWithIngredients_WhenIngredientsWereAdded() { var ingredient1 = new Ingredient{ Name = "ingredient1", Price = 10}; var ingredient2 = new Ingredient {Name = "ingredient2", Price = 20}; _ingreditentsRepository.Persist(ingredient1); _ingreditentsRepository.Persist(ingredient2); var expectedPizza = new Pizza { Name = "pizza1", Price = 123.12M, PizzasIngredients = new List<PizzasIngredients>() { new PizzasIngredients {IngredientId = ingredient1.Id.Value}, new PizzasIngredients {IngredientId = ingredient2.Id.Value} } }; var pizzaDb = _sut.Persist(expectedPizza); var result = _sut.GetByIdWithToppings(pizzaDb.Id.Value); Assert.That(result, Is.Not.Null); CollectionAssert.IsNotEmpty(result.PizzasIngredients); Assert.That(result.PizzasIngredients.Count, Is.EqualTo(expectedPizza.PizzasIngredients.Count)); }
public void GetByIdWithToppingsd_ShouldReturnEmptyCollectionOfIngredients_WhenIngredientsWereNotDefined() { var expectedPizza = new Pizza { Name = "pizza2", Price = 222M }; var pizzaDb = _sut.Persist(expectedPizza); var result = _sut.GetByIdWithToppings(pizzaDb.Id.Value); Assert.That(result, Is.Not.Null); CollectionAssert.IsEmpty(result.PizzasIngredients); }
public Pizza Add(Pizza pizza) { if (pizza.PizzasIngredients == null || !pizza.PizzasIngredients.Any()) { throw new ArgumentException("The pizza has to contain toppings."); } var pizzaDb = _pizzasRepository.Persist(pizza); if (pizzaDb != null && pizzaDb.Id.HasValue) { return Get(pizzaDb.Id.Value); } return null; }
public void GetAllWithToppings_ShouldReturnAllPizzasWithIngredients_WhenIngredientsWereAdded() { var ingredient1 = new Ingredient { Name = "ingredient1", Price = 10 }; var ingredient2 = new Ingredient { Name = "ingredient2", Price = 20 }; _ingreditentsRepository.Persist(ingredient1); _ingreditentsRepository.Persist(ingredient2); var Pizza1 = new Pizza { Name = "pizza1", Price = 123.12M, PizzasIngredients = new List<PizzasIngredients>() { new PizzasIngredients {IngredientId = ingredient1.Id.Value}, new PizzasIngredients {IngredientId = ingredient2.Id.Value} } }; var Pizza2 = new Pizza { Name = "pizza1", Price = 123.12M, PizzasIngredients = new List<PizzasIngredients>() { new PizzasIngredients {IngredientId = ingredient1.Id.Value}, new PizzasIngredients {IngredientId = ingredient2.Id.Value} } }; _pizzasRepository.Persist(Pizza1); _pizzasRepository.Persist(Pizza2); var expectedPizzas = new List<Pizza>(); expectedPizzas.Add(Pizza1); expectedPizzas.Add(Pizza2); var result = _sut.GetAllWithToppings(); Assert.That(result, Is.Not.Null); CollectionAssert.IsNotEmpty(result); Assert.That(result.Count(), Is.EqualTo(expectedPizzas.Count)); }
public IHttpActionResult DeletePizza(int id) { var pizza = new Pizza {Id = id}; _pizzaService.Remove(pizza); return Ok(); }
public void Remove(Pizza pizza) { _pizzasRepository.Remove(pizza); }