public void DeleteWithIdThatDoesntExistThrowsException()
        {
            int id = 1000;
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_pizza_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            //using (var db = new Project1Context(options))
            //{
            //var repo = new PizzaRepository(db);

            //Pizzas Pizza = new Pizzas { Name = "Test Delete", Stock = 10 };
            //repo.Save(Pizza);
            //repo.SaveChanges();
            //id = Pizza.Id;
            //}

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var    repo  = new PizzaRepository(db);
                Pizzas Pizza = (Pizzas)repo.GetById(id);

                Assert.Null(Pizza);

                Assert.Throws <ArgumentException>(() => repo.Delete(id));
            }
        }
Esempio n. 2
0
        public void DeleteExistingPizza()
        {
            var allPizzas   = _sut.Get().ToList();
            var pizzasCount = allPizzas.Count;
            var pizza       = allPizzas.First();

            _sut.Delete(pizza);

            Assert.Equal(pizzasCount - 1, _sut.Get().Count());
        }
        public void DeleteWorks()
        {
            int id = 0;

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_pizza_test_delete").Options;

            using (var db = new Project1Context(options));

            // act (for act, only use the repo, to test it)
            using (var db = new Project1Context(options))
            {
                var repo = new PizzaRepository(db);
                var ingredientRepository = new IngredientRepository(db);

                Ingredients ingredient = new Ingredients()
                {
                    Name = "Ingredient", Stock = 10
                };
                ingredientRepository.Save(ingredient);
                ingredientRepository.SaveChanges();

                Pizzas pizza = new Pizzas
                {
                    Name  = "Pizza 1",
                    Price = 20,
                };
                pizza.PizzasIngredients.Add(new PizzasIngredients()
                {
                    IngredientId = ingredient.Id
                });
                repo.Save(pizza);
                repo.SaveChanges();
                id = pizza.Id;
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var    repo  = new PizzaRepository(db);
                Pizzas pizza = (Pizzas)repo.GetById(id);

                Assert.NotEqual(0, pizza.Id);
                Assert.Equal("Pizza 1", pizza.Name);
                Assert.Equal(20, pizza.Price);

                repo.Delete(id);
                repo.SaveChanges();
                pizza = (Pizzas)repo.GetById(id);

                Assert.Null(pizza);
            }
        }
        public IActionResult Delete([FromBody] Pizza pizza)
        {
            if (pizza == null)
            {
                return(new ContentResult
                {
                    Content = "Missing id/name",
                    StatusCode = 404
                });
            }

            _pizzaRepository.Delete(pizza);

            return(new ContentResult
            {
                StatusCode = 204
            });
        }
Esempio n. 5
0
 public bool Delete([FromUri] int id)
 {
     return(_pizzaRepository.Delete(id));
 }
Esempio n. 6
0
 // DELETE
 public bool DeletePizza(Pizza p)
 {
     return(_pr.Delete(p, _ctx));
 }