Ejemplo n.º 1
0
        public async void TestPizzaRepositoryGetAll()
        {
            await _connection.OpenAsync();

            await dbo.Database.EnsureCreatedAsync();

            PizzaModel tempPizza = new PizzaModel()
            {
                Crust = new CrustModel {
                    Name = "garlic", Description = "delicousness"
                }, Size = new SizeModel {
                    Name = "large", Diameter = 16
                }, Toppings = new System.Collections.Generic.List <ToppingsModel> {
                    new ToppingsModel {
                        Name = "onions", Description = "they have layers"
                    }
                }, Name = "shrek", Description = "right form the swamp", SpecialPizza = true
            };

            dbo.Pizzas.Add(tempPizza);
            dbo.SaveChanges();
            PizzaRepository PR = new PizzaRepository(dbo);

            Assert.NotNull(PR.GetAll());
        }
        public void SetUp()
        {
            var database = new Mock <IDatabase>();

            database.Setup(x => x.Query <PizzaRecord>()).Throws(new Exception("Something went wrong"));

            var subject = new PizzaRepository(database.Object);

            _result = subject.GetAll();
        }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            // Henter all pizza'erne
            var pizzaRepository = new PizzaRepository();
            var pizzaList       = pizzaRepository.GetAll();

            // Indsætter alle pizza'er inde i viewModel
            var viewModel = new PizzaViewModel();

            viewModel.Pizzas      = pizzaList;
            viewModel.OrderdPizza = Session["shoppingCart"] as List <OrderPizza>;
            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public ActionResult Menu(string pizzaFilter = null)
        {
            var pizzas = _pizzaRepository.GetAll();

            if (!string.IsNullOrWhiteSpace(pizzaFilter))
            {
                pizzas = pizzas
                         .Where(x => x.Name.StartsWith(pizzaFilter, StringComparison.CurrentCultureIgnoreCase))
                         .ToList();
            }

            ViewBag.pizzaFilter = pizzaFilter;

            return(View(pizzas));
        }
Ejemplo n.º 5
0
        public IActionResult Home()
        {
            var repo = new PizzaRepository(_db);

            /*
             * PizzaFactory pf = new PizzaFactory();
             * var tempPizza = pf.Create();
             * tempPizza.Name = "cheese";
             * tempPizza.Description ="the cheesiest of pizzas";
             * tempPizza.Crust= new CrustModel{Name ="thin",Description = "a thin crusted pizza"};
             * tempPizza.Size = new SizeModel{Name = "small",Diameter =10};
             * tempPizza.Toppings= new List<ToppingsModel>{new ToppingsModel(){Name = "cheese",Description ="the cheeseiest of toppings"}};
             * repo.Add(tempPizza);*/
            ViewBag.PizzaList = repo.GetAll();
            return(View("Home"));
        }
        public void GetAllWorks()
        {
            List <Pizzas> list = new List <Pizzas>();

            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <Project1Context>()
                          .UseInMemoryDatabase("db_pizza_test_getAll").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);

                for (int i = 0; i < 5; i++)
                {
                    Pizzas pizza = new Pizzas
                    {
                        Name  = $"Pizza {i}",
                        Price = 20
                    };
                    list.Add(pizza);
                    repo.Save(pizza);
                }
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly for verify.)
            using (var db = new Project1Context(options))
            {
                var           repo   = new PizzaRepository(db);
                List <Pizzas> Pizzas = (List <Pizzas>)repo.GetAll();

                Assert.Equal(list.Count, Pizzas.Count);

                for (int i = 0; i < list.Count; i++)
                {
                    Assert.Equal(list[i].Name, Pizzas[i].Name);
                    Assert.Equal(list[i].Price, Pizzas[i].Price);
                }
            }
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            var database = new Mock <IDatabase>();

            database.Setup(x => x.Query <PizzaRecord>()).Returns(new List <PizzaRecord>
            {
                new PizzaRecord
                {
                    Id   = 1,
                    Name = "Original"
                },
                new PizzaRecord
                {
                    Id   = 2,
                    Name = "Gimme the Meat"
                }
            });

            var subject = new PizzaRepository(database.Object);

            _result = subject.GetAll();
        }
Ejemplo n.º 8
0
        public ActionResult Index()
        {
            var list = m_PizzaRepository.GetAll();

            return(View(list));
        }
Ejemplo n.º 9
0
 public IEnumerable <Pizza> Get()
 {
     return(_repo.GetAll());
 }