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 Remove_ShouldRemoveIngredientFromRepository() { var ingredient = new Ingredient(); _sut.Remove(ingredient); A.CallTo(() => _ingredientsRepository.Remove(A<Ingredient>._)) .MustHaveHappened(); }
public void Add_ShouldPersistIngredientInRepository() { var ingredient = new Ingredient(); _sut.Add(ingredient); A.CallTo(() => _ingredientsRepository.Persist(A<Ingredient>._)) .MustHaveHappened(); }
public void Persisted_Data_Should_Be_Accesible_By_Id_Via_FindById() { var someTransientModel = new Ingredient { Id = null, Name = "Ing4", Price = 155M }; var persisted = _sut.Persist(someTransientModel); var actual = _sut.FindById(persisted.Id.Value); Assert.That(actual.Id, Is.EqualTo(persisted.Id)); Assert.That(actual.Price, Is.EqualTo(persisted.Price)); Assert.That(actual.Name, Is.EqualTo(persisted.Name)); }
public void Add_ShouldReturnIngredientFromRepository() { var expectedIngredient = new Ingredient(); A.CallTo(() => _ingredientsRepository.Persist(A<Ingredient>._)) .Returns(expectedIngredient); var result = _sut.Add(expectedIngredient); A.CallTo(() => _ingredientsRepository.Persist(A<Ingredient>._)) .MustHaveHappened(); Assert.That(result, Is.EqualTo(expectedIngredient)); }
public void GetAll_Returns_All_Items() { var model1 = new Ingredient { Id = null, Name = "Ing1", Price = 100.22M}; var model2 = new Ingredient { Id = null, Name = "Ing2", Price= 100.11M}; _sut.Persist(model1); _sut.Persist(model2); var result = _sut.GetAll(); Assert.That(result.Count(), Is.EqualTo(2)); CollectionAssert.AllItemsAreUnique(result); }
public void Persist_Should_Return_Copy_Of_Transient_Object_With_Id_Assigned() { var someTransientModel = new Ingredient { Id = null, Name = "Ing3", Price = 55M }; var result = _sut.Persist(someTransientModel); Assert.That(result, Is.Not.Null); Assert.That(result, Is.Not.SameAs(someTransientModel)); Assert.That(result.Price, Is.EqualTo(someTransientModel.Price)); Assert.That(result.Name, Is.EqualTo(someTransientModel.Name)); Assert.That(result.Id.HasValue); }
public void Persisted_Object_With_Already_Existing_Id_Should_Evict_Previus_Data() { var someTransientModel = new Ingredient { Id = null, Name = "Ing5", Price = 255M }; var persisted = _sut.Persist(someTransientModel); var anotherWithSameId = new Ingredient { Id = someTransientModel.Id, Name = "Ing6", Price = 355M }; _sut.Persist(anotherWithSameId); var actual = _sut.FindById(persisted.Id.Value); Assert.That(actual.Id, Is.EqualTo(persisted.Id)); Assert.That(actual.Price, Is.EqualTo(anotherWithSameId.Price)); Assert.That(actual.Name, Is.EqualTo(anotherWithSameId.Name)); }
public async void GetIngredient_ShouldReturnStatusCodeOk_WhenTheIngredientWasFound() { var ingredient = new Ingredient { Id = 2, Name = "ingredientName", Price = 123.2M }; A.CallTo(() => _ingredientService.Get(A<int>._)).Returns(ingredient); var result = _sut.GetIngredient(int.MaxValue); var response = await result.ExecuteAsync(CancellationToken.None); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); }
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 RemoveIngredient(int id) { var ingredient = new Ingredient {Id = id }; _ingredientService.Remove(ingredient); return Ok(); }
public void Remove_Should_Remove_Item_Of_Same_Id_From_Storage() { var someTransientModel = new Ingredient { Id = null, Name = "Ing7", Price = 555M }; var persisted = _sut.Persist(someTransientModel); var anotherWithSameId = new Ingredient { Id = persisted.Id }; _sut.Remove(anotherWithSameId); var actual = _sut.FindById(persisted.Id.Value); Assert.That(actual, Is.Null); }
public void Subsequent_Persist_Calls_Objects_Should_Assign_Different_Id() { var someTransientModel = new Ingredient { Id = null, Name = "Ing8", Price = 655M }; var anotherTransientModel = (Ingredient)someTransientModel.Clone(); var result1 = _sut.Persist(someTransientModel); var result2 = _sut.Persist(anotherTransientModel); Assert.That(result1, Is.Not.Null); Assert.That(result2, Is.Not.Null); Assert.That(result1, Is.Not.SameAs(someTransientModel)); Assert.That(result2, Is.Not.SameAs(someTransientModel)); Assert.That(result1, Is.Not.SameAs(result2)); Assert.That(result1.Id, Is.Not.Null); Assert.That(result2.Id, Is.Not.Null); Assert.That(result1.Id, Is.Not.EqualTo(result2.Id)); }
public void Remove(Ingredient ingredient) { _ingredinetRepository.Remove(ingredient); }
public Ingredient Add(Ingredient ingredient) { return _ingredinetRepository.Persist(ingredient); }