Beispiel #1
0
        public static void Main()
        {
            var factories = new PizzaFactory[]
            {
                new CheesePizzaFactory(),
                new PepperoniPizzaFactory(),
                new HawaiPizzaFactory()
            };

            foreach (var factory in factories)
            {
                Pizza pizza = factory.CreatePizza();

                var factoryName = factory.GetType().Name;
                Console.WriteLine(PrintMessages.PizzaFactory, pizza.Description, factoryName);
            }
        }
Beispiel #2
0
        private void abstractFactoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateOutput("A factory will be created that will return an abstract instance depending on the variable passed in.");
            PizzaFactory  pizzaFactory = new PizzaFactory();
            PizzaAbstract pizza;

            pizza = pizzaFactory.OrderPizza(Pizzas.Chicken);
            UpdateOutput(pizza.Prepare());

            pizza = pizzaFactory.OrderPizza(Pizzas.MeatLovers);
            UpdateOutput(pizza.Prepare());

            pizza = pizzaFactory.OrderPizza(Pizzas.Pepperoni);
            UpdateOutput(pizza.Prepare());

            UpdateOutput("");
        }
        public static PizzaModel AssignIngredients(PizzaModel model, List <IngredientModel> ingredients)
        {
            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            foreach (var ing in ingredients)
            {
                PizzaIngredientModel pizIng = new PizzaIngredientModel
                {
                    Id         = new Guid(),
                    Ingredient = ing,
                    PizzaId    = model.Id
                };
                unitOfWork.PizzaIngredientRepository.AddPizza_Ingredients(PizzaIngredientFactory.ConvertPizzaIngredientModel(pizIng));
                model.PizzaIngredients.Add(pizIng);
            }
            unitOfWork.PizzaRepository.UpdatePizza(PizzaFactory.ConvertPizzaModel(model));
            return(model);
        }
        public static void OrderOrder(OrderViewModel model)
        {
            var pizza       = PizzaFactory.ConvertPizzaModel(model.pizza);
            var bottom      = BottomFactory.ConvertBottom(model.bottom);
            var sauce       = SauceFactory.ConvertSauce(model.sauce);
            var ingredients = IngredientFactory.ConvertIngredientModels(model.ingredients);

            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            unitOfWork.BottomRepository.RemoveBottom(bottom.Id);
            unitOfWork.PizzaRepository.RemovePizza(pizza.Id);
            unitOfWork.SauceRepository.RemoveSauce(sauce.Id);

            foreach (var ing in ingredients)
            {
                unitOfWork.IngredientRepository.RemoveIngredient(ing.Id);
            }
        }
Beispiel #5
0
        public static Menu GetMenu()
        {
            if (_instance is null)
            {
                ProductFactory           pizzaFactory      = new PizzaFactory();
                ItemFactory <Soda>       sodaFactory       = new SodaFactory();
                ItemFactory <Ingredient> ingredientFactory = new IngredientFactory();

                _instance = new Menu()
                {
                    Pizzas = new List <Product>
                    {
                        pizzaFactory.GetProduct(nameof(Margherita)),
                        pizzaFactory.GetProduct(nameof(Hawaii)),
                        pizzaFactory.GetProduct(nameof(Kebabpizza)),
                        pizzaFactory.GetProduct(nameof(QuatroStagioni))
                    },
                    Sodas = new List <Soda>
                    {
                        sodaFactory.GetItem(nameof(Fanta)),
                        sodaFactory.GetItem(nameof(CocaCola)),
                        sodaFactory.GetItem(nameof(Sprite))
                    },
                    Ingredients = new List <Ingredient>
                    {
                        ingredientFactory.GetItem(nameof(Ham)),
                        ingredientFactory.GetItem(nameof(Pineapple)),
                        ingredientFactory.GetItem(nameof(Mushrooms)),
                        ingredientFactory.GetItem(nameof(Onion)),
                        ingredientFactory.GetItem(nameof(KebabSauce)),
                        ingredientFactory.GetItem(nameof(Shrimps)),
                        ingredientFactory.GetItem(nameof(Mussels)),
                        ingredientFactory.GetItem(nameof(Artichoke)),
                        ingredientFactory.GetItem(nameof(Kebab)),
                        ingredientFactory.GetItem(nameof(Coriander)),
                    }
                };
            }

            return(_instance);
        }
Beispiel #6
0
        public void FactoryGeneratesPizzaWithConfig()
        {
            var baseName          = "Test Base";
            var cookingMultiplier = 1;
            var toppingName       = "Test Topping";


            var config = new CoreConfiguration
            {
                PizzasToMake       = 1,
                BaseConfigurations = new[]
                {
                    new BaseConfiguration
                    {
                        Name = baseName,
                        CookingMultiplier = cookingMultiplier
                    }
                },
                ToppingConfigurations = new[]
                {
                    new ToppingConfiguration
                    {
                        Name = toppingName
                    }
                }
            };

            _mockOptions.Setup(x => x.Value).Returns(config);
            var pizzaFactory = new PizzaFactory(_mockOptions.Object);

            // Act
            var pizzas = pizzaFactory.GeneratePizzas();

            // Assert
            var pizza = pizzas.FirstOrDefault();

            Assert.IsNotNull(pizza);
            Assert.AreEqual(baseName, pizza.Base.Name);
            Assert.AreEqual(cookingMultiplier, pizza.Base.CookingMultiplier);
            Assert.AreEqual(toppingName, pizza.Topping.Name);
        }
        public IActionResult PlaceOrder(PizzaViewModel pizzaViewModel)
        {
            var crust = _db.Crusts.FirstOrDefault(c => c.Name == pizzaViewModel.Crust);
            var size  = _db.Sizes.FirstOrDefault(s => s.Name == pizzaViewModel.Size);
            List <ToppingModel> toppings = new List <ToppingModel>();

            foreach (var topping in pizzaViewModel.SelectedToppings)
            {
                var top = _db.Toppings.FirstOrDefault(t => t.Name == topping);
                toppings.Add(top);
            }
            PizzaFactory pf       = new PizzaFactory();
            var          pizza    = pf.Create() as PizzaModel;
            var          newPizza = pf.Update(pizza, crust, size, toppings) as PizzaModel;

            OrderViewModel orderViewModel = new OrderViewModel();

            orderViewModel.AddPizza(newPizza);

            return(View("ShowOrder", orderViewModel));
        }
        public void CreatePizzaTest()
        {
            var expected = "Margerita";
            var pizza    = PizzaFactory.CreatePizza("1");
            var actual   = pizza.GetName();

            Assert.AreEqual(expected, actual);

            expected = "Hawaii";
            pizza    = PizzaFactory.CreatePizza("2");
            actual   = pizza.GetName();
            Assert.AreEqual(expected, actual);

            expected = "KebabPizza";
            pizza    = PizzaFactory.CreatePizza("3");
            actual   = pizza.GetName();
            Assert.AreEqual(expected, actual);

            expected = "Quatro Stagioni";
            pizza    = PizzaFactory.CreatePizza("4");
            actual   = pizza.GetName();
            Assert.AreEqual(expected, actual);
        }
Beispiel #9
0
        public Pizza Order(PizzaTypes type, IEnumerable <ToppingType> withToppings = null)
        {
            var pizza = PizzaFactory.CreatePizza(type);

            if (pizza == null)
            {
                Console.WriteLine($"Selected {type} Pizza is not available at {Location}");
                return(null);
            }
            if (withToppings != null && withToppings.Any())
            {
                foreach (var toppingType in withToppings)
                {
                    var topping = ToppingsFactory.CreateTopping(toppingType);
                    pizza.Toppings.Add(topping);
                }
            }
            pizza.Prepare();
            pizza.Bake();
            pizza.Cut();
            pizza.Box();
            return(pizza);
        }
Beispiel #10
0
        public void Run()
        {
            try
            {
                string[] pizzaElements = Console.ReadLine()
                                         .Split(" ")
                                         .ToArray();

                string[] doughElements = Console.ReadLine()
                                         .Split(" ")
                                         .ToArray();

                Dough dough = DoughFactory.Create(doughElements);

                Pizza pizza = PizzaFactory.Create(pizzaElements, dough);

                string input = string.Empty;

                while ((input = Console.ReadLine()) != "END")
                {
                    string[] toppingElements = input
                                               .Split(" ")
                                               .ToArray();

                    Topping topping = ToppingFactory.Create(toppingElements);

                    pizza.AddTopping(topping);
                }

                Console.WriteLine(pizza);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #11
0
 public ClamPizza(PizzaFactory source) : base(source, "Clam Pizza")
 {
 }
Beispiel #12
0
        public void TakeOrder(string[] ingredients)
        {
            var pizza = PizzaFactory.MakePizza(ingredients);

            PizzaOven.PreparePizza(new PizzaToMenuAdapter(pizza));
        }
        public void ShouldReturnNullIfInvalidPizzaType()
        {
            IPizza pizza = PizzaFactory.CreatePizza(PizzaType.UnKnown);

            Assert.IsNull(pizza);
        }
Beispiel #14
0
        public void ConvertRegular(PizzaViewModel pizzaViewModel, PizzaStoreDBContext _db)
        {
            var UR  = new UserRepository(_db);
            var STR = new StoreRepository(_db);
            var OR  = new OrderRepository(_db);
            var CR  = new CrustRepository(_db);
            var SR  = new SizeRepository(_db);
            var PR  = new PizzaRepository(_db);
            var TR  = new ToppingRepository(_db);
            var PF  = new PizzaFactory();
            List <ToppingsModel> TM = new List <ToppingsModel>();

            SelectedToppings = new List <CheckBoxTopping>();

            foreach (var t in Toppings2)
            {
                if (t.IsSelected)
                {
                    SelectedToppings.Add(t);
                }
            }
            foreach (var t in SelectedToppings)
            {
                var throwaway   = TR.Get(t.Text);
                var tempTopping = new ToppingsModel()
                {
                    Name = throwaway.Name, Description = throwaway.Description
                };
                TM.Add(tempTopping);
            }

            //TM.Add(TR.Get(Topping));
            var tempPizza = PF.Create();

            tempPizza.Name         = "custom";
            tempPizza.Description  = "custom";
            tempPizza.Size         = SR.Get(pizzaViewModel.Size);
            tempPizza.Crust        = CR.Get(pizzaViewModel.Crust);
            tempPizza.Toppings     = new List <ToppingsModel>();
            tempPizza.Toppings     = TM;
            tempPizza.SpecialPizza = false;
            var cart = OR.GetCurrentOrder();
            var OF   = new OrderFactory();

            if (cart != null)
            {
                OR.AddPizza(cart.Id, tempPizza);
            }
            else
            {
                cart = OF.Create();

                cart.Pizzas = new List <PizzaModel>();
                cart.Pizzas.Add(tempPizza);
                cart.CurrentOrder = true;
                OR.UpdateCurrentOrder(cart);
                var tempUser = UR.Get(User);
                UR.AddOrder(tempUser.Id, cart);
                var tempStore = STR.Get(Store);
                STR.AddOrder(tempStore.Id, cart);
            }
        }
 public void ShouldCreateASausagePizza()
 {
     IPizza pizza = PizzaFactory.CreatePizza(PizzaType.Sausage);
     //Assert.Contains(pizza.Toppings, PizzaType.Cheese.ToString());
     //Assert.Contains(pizza.Toppings, PizzaType.Sausage.ToString());
 }
 public void ShouldCreateAPepperoniPizza()
 {
     IPizza pizza = PizzaFactory.CreatePizza(PizzaType.Pepperoni);
     //Assert.Contains(pizza.Toppings, PizzaType.Cheese.ToString());
     //Assert.Contains(pizza.Toppings, PizzaType.Pepperoni.ToString());
 }
 public PizzaFactoryTests()
 {
     _pizzaFactory = new PizzaFactory(_mockLogger.Object, _mockConfig.Object, _mockTimer.Object, _mockWriter.Object);
 }
 public OnlineDeliveryCompany(PizzaFactory pizzaFactory)
 {
     this.factory = pizzaFactory;
 }
Beispiel #19
0
 protected override IPizza CreateLocalizedPizza(PizzaType type) =>
 PizzaFactory.CreateLocalizedPizza(type, Ingredients);
 public NYPizzaStore(PizzaFactory _factory) : base(_factory)
 {
     factory = _factory;
 }
Beispiel #21
0
        public void CreateMargaritaPizza() // Facts cann't receive parameters
        {
            IPizza p = new PizzaFactory().CreatePizza(PizzaTypes.MargarinaPizza);

            Assert.True(p != null && p.PizzaDescription() == "Margarina pizza");
        }
 public PizzaStore(PizzaFactory _factory) 
 {
     factory = _factory;
 }
Beispiel #23
0
 static void Main()
 {
     var param1 = new Pizza1Parameter();
     var p1     = PizzaFactory.CreatePizza(PizzaFactory.PizzaType.Pizza1, param1);
 }
Beispiel #24
0
        public void TakeOrder(string[] ingredients, string drink, double price)
        {
            var pizza = PizzaFactory.MakePizza(ingredients);

            PizzaOven.PreparePizza(new PizzaToMenuAdapter(drink, price, pizza));
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            Type t = typeof(Action);

            Console.WriteLine(t.IsClass);

            // Func Action Example
            ProductFactory productFactory = new ProductFactory();

            ;
            WrapFactory wrapFactory = new WrapFactory();

            Logger           logger = new Logger();
            Action <Product> log    = new Action <Product>(logger.Log);


            Func <Product> func1 = productFactory.MakePizza;
            Func <Product> func2 = new Func <Product>(productFactory.MakeToyCar);

            // pattern method, func1 delegate methode can bring different procduct ( you can chang product by design productFactory, adding more product)
            // callback method,hollywood method, if I choose, i will call you.
            Box box1 = wrapFactory.WrapProduct(func1, log);
            Box box2 = wrapFactory.WrapProduct(func2, log);

            Console.WriteLine(box1.Product.Name);
            Console.WriteLine(box2.Product.Name);


            //  interface example
            IProductFactory      pizzaFactory         = new PizzaFactory();
            IProductFactory      toycarFactory        = new ToyCarFactory();
            WrapFactoryInterface wrapFactoryInterface = new WrapFactoryInterface();
            Box box3 = wrapFactoryInterface.WrapProduct(pizzaFactory);
            Box box4 = wrapFactoryInterface.WrapProduct(toycarFactory);

            Console.WriteLine(box3.Product.Name);
            Console.WriteLine(box4.Product.Name);

            //----------------------------------------------------------------------------------
            // sample for multicast delegate

            Student stu1 = new Student()
            {
                ID = 1, PenColor = ConsoleColor.Blue
            };
            Student stu2 = new Student()
            {
                ID = 2, PenColor = ConsoleColor.Yellow
            };
            Student stu3 = new Student()
            {
                ID = 3, PenColor = ConsoleColor.Red
            };
            Student stu4 = new Student()
            {
                ID = 4, PenColor = ConsoleColor.Green
            };

            Action action1 = new Action(stu1.DoHomework);
            Action action2 = new Action(stu2.DoHomework);
            Action action3 = new Action(stu3.DoHomework);
            Action action4 = new Action(stu4.DoHomework);

            action1 += action2;
            action1 += action3;
            action1 += action4;
            action1();

            // throw exception
            //action1.BeginInvoke(null, null);
            //action2.BeginInvoke(null, null);
            //action3.BeginInvoke(null, null);
            //action4.BeginInvoke(null, null);

            Thread thread1 = new Thread(new ThreadStart(stu1.DoHomework));
            Thread thread2 = new Thread(new ThreadStart(stu2.DoHomework));
            Thread thread3 = new Thread(new ThreadStart(stu3.DoHomework));

            thread1.Start();
            thread2.Start();
            thread3.Start();
            Console.WriteLine("*******************************");

            Task task1 = new Task(new Action(stu2.DoHomework));
            Task task2 = new Task(new Action(stu3.DoHomework));
            Task task3 = new Task(new Action(stu4.DoHomework));

            Console.WriteLine("*******************************");
            task1.Start();
            task2.Start();
            task3.Start();
        }
Beispiel #26
0
        // [ValidateAntiForgeryToken]
        public IActionResult Post(PizzaViewModel pizzaViewModel, int id) //model binding
        {
            var return_view = "";

            switch (id)
            {
            case 1:       // set return view for standard pizza orders

                return_view = "OrderStandard";
                break;

            case 2:       // set return view for custom pizza orders
                pizzaViewModel.Type = "Custom";
                return_view         = "OrderCustom";
                break;

            default:
                break;
            }
            ;

            if (ModelState.IsValid)                //  what is the validation? (add to viewmodel)
            {
                var        p = new PizzaFactory(); // use dependency injection
                PizzaModel domainPizzaModel = new PizzaModel();
                domainPizzaModel = p.Create();     // factory-created Domain PizzaModel

                if (pizzaViewModel.Types.Contains(pizzaViewModel.Type) || pizzaViewModel.Type == "Custom")
                {
                    switch (id)
                    {
                    case 1:                                                                                        //standard pizza chosen
                        pizzaViewModel.SelectedToppings.Clear();
                        pizzaViewModel.SelectedToppings.AddRange(pizzaViewModel.ToppingSets[pizzaViewModel.Type]); // add topping sets based on chosen pizza type
                        break;

                    case 2: //custom pizza chosen
                        if (pizzaViewModel.SelectedToppings.Contains("dummy"))
                        {
                            return(View(return_view, pizzaViewModel));      // no toppings were chosen at all, return to custom pizza order page
                        }
                        break;

                    default:
                        break;
                    }

                    var pricepertopping = 1.0m;
                    switch (id)
                    {
                    case 1:   // set prices for standard pizza orders
                        domainPizzaModel.Price = pizzaViewModel.Prices[pizzaViewModel.Type];
                        break;

                    case 2:                                                        // set prices for custom pizza orders
                        domainPizzaModel.Price  = pizzaViewModel.Prices["Cheese"]; //cheapest
                        domainPizzaModel.Price += pizzaViewModel.SelectedToppings.Count * pricepertopping;
                        break;

                    default:
                        break;
                    }
                    ;
                }
                else
                {
                    domainPizzaModel.Price = pizzaViewModel.Prices["Cheese"]; //cheapest
                    pizzaViewModel.SelectedToppings.AddRange(pizzaViewModel.ToppingSets["Cheese"]);
                }

                // bind PizzaViewModel to Domain PizzaModel
                domainPizzaModel.Name = pizzaViewModel.Type;

                var newC = new CrustModel();
                newC.Name = pizzaViewModel.Crust;
                domainPizzaModel.Crust = newC;

                var newS = new SizeModel();
                newS.Name             = pizzaViewModel.Size;
                domainPizzaModel.Size = newS;

                foreach (var t in pizzaViewModel.SelectedToppings)
                {
                    var newToppings = new List <ToppingModel>();
                    var newTopping  = new ToppingModel();
                    newTopping.Name = t;
                    domainPizzaModel.Toppings.Add(newTopping);
                }

                var repo_pizza = new PizzaRepository();
                repo_pizza.Create(domainPizzaModel, _db);

                return_view = "ThankYou";
                return(View(return_view));
            }


            return(View(return_view, pizzaViewModel));
        }
Beispiel #27
0
 protected PizzaStore(PizzaFactory factory, string name)
 {
     innerFactory = factory;
     Name         = name;
 }
Beispiel #28
0
 public SimplePizza(String name, PizzaFactory pizzaFactory)
 {
     _name         = name;
     _pizzaFactory = pizzaFactory;
 }
 public void Update(PizzaFactory PizzaTopping)
 {
     _DBContext.PizzaToppings.Update(PizzaTopping);
 }
Beispiel #30
0
        public void CreateBBqPizza() // Facts cann't receive parameters
        {
            IPizza p = new PizzaFactory().CreatePizza(PizzaTypes.BbqPizza);

            Assert.True(p != null && p.PizzaDescription() == "Barbacue pizza");
        }
Beispiel #31
0
 public PizzaStore(PizzaFactory factory)
 {
     this.factory = factory;
 }
Beispiel #32
0
 public OnlineDeliveryCompany(PizzaFactory pizzaFactory)
 {
     factory = pizzaFactory;
 }
 /// <summary>
 /// Creates the pizza(Template).
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CreatePizza_Click(object sender, RoutedEventArgs e)
 {
     this.pizza            = PizzaFactory.CreatePizza(PizzaSize.Medium);
     this.PizzaLbl.Text    = this.pizza.ToString();
     this.PriceLbl.Content = string.Format("Price: {0:C}", this.pizza.CalculatePrice());
 }