Пример #1
0
        public static IOrderable CreatePizza(string type)
        {
            IOrderable chosenPizza;

            switch (type)
            {
            case "1":
                chosenPizza = new Margerita();
                return(chosenPizza);

            case "2":
                chosenPizza = new Hawaii();
                return(chosenPizza);

            case "3":
                chosenPizza = new KebabPizza();
                return(chosenPizza);

            case "4":
                chosenPizza = new QuatroStagioni();
                return(chosenPizza);

            default:
                throw new NotSupportedException();
            }
        }
Пример #2
0
        public void DecoratorTest()
        {
            IOrderable pizza         = new Margerita();
            IOrderable ham           = new Ham(pizza);
            IOrderable kebab         = new Kebab(ham);
            IOrderable onion         = new Onion(kebab);
            var        expectedPizza = $"Margerita{Environment.NewLine} with ham{Environment.NewLine} with kebab{Environment.NewLine} with onion";
            var        expectedPrice = 125;
            var        actualPizza   = onion.GetName();
            var        actualPrice   = onion.GetPrice();

            Assert.AreEqual(expectedPizza, actualPizza);
            Assert.IsTrue(expectedPrice == actualPrice);
        }