Example #1
0
        static void Main(string[] args)
        {
            BevarageBase espresso = new Espresso();
            BevarageBase blackTea = new BlackTea();
            BevarageBase greenTea = new GreenTea();

            PrintBeverage(espresso);
            PrintBeverage(blackTea);
            PrintBeverage(greenTea);


            Console.WriteLine("----------");


            BevarageBase capuccino = new SugarCondiment(new MilkCondiment(new Espresso()));

            PrintBeverage(capuccino);


            BevarageBase greenTeaWithSugar = new SugarCondiment(new GreenTea());

            PrintBeverage(greenTeaWithSugar);


            Console.ReadKey();
        }
Example #2
0
        public void Exec()
        {
            Tea greanTea = new GreenTea();

            greanTea = new TeaCream(greanTea);
            greanTea = new TeaMilk(greanTea);

            var test1 = greanTea.Price;
        }
Example #3
0
        static void Main(string[] args)
        {
            BeverageBase capuccino     = new Capuccino();
            BeverageBase tea           = new Tea();
            BeverageBase hot_chololate = new HotChocolate();
            BeverageBase espresso      = new Espresso();


            List <BeverageBase> beverage_list = new List <BeverageBase>();

            beverage_list.Add(capuccino);
            beverage_list.Add(tea);
            beverage_list.Add(hot_chololate);
            beverage_list.Add(espresso);


            foreach (BeverageBase beverage in beverage_list)
            {
                Console.WriteLine("Beverage: {0}, price: {1}", beverage.GetDescription(), beverage.GetPrice());
                Console.WriteLine();
            }



            Console.WriteLine("______________________________");



            BeverageBase green_tea = new GreenTea();


            BeverageBase capuccino2 = new AdditionSugar(new AdditionMilk(new Espresso()));


            beverage_list.Add(capuccino2);


            foreach (BeverageBase beverage in beverage_list)
            {
                Console.WriteLine("Beverage: {0}, price: {1}", beverage.GetDescription(), beverage.GetPrice());
                Console.WriteLine();
            }



            Console.ReadKey();
        }
        public void buyGreenTeaAndHoneyAndMilkAndChocolateTest()
        {
            GreenTea  greenTea  = new GreenTea();
            Honey     honey     = new Honey();
            Milk      milk      = new Milk();
            Chocolate chocolate = new Chocolate();

            customer.buy(greenTea);
            customer.buy(honey);
            customer.buy(milk);
            customer.buy(chocolate);

            string actual = customer.print();
            string expect = "GreenTea(22.00)+Honey(4.50)+Milk(3.50)+Chocolate(7.00) | Total=37.00";

            Assert.AreEqual(expect, actual);
        }
Example #5
0
        static void Main(string[] args)
        {
            BeverageBase blackTea = new BlackTea();
            BeverageBase greenTea = new GreenTea();
            BeverageBase coffee   = new Coffee();

            Display(blackTea);
            Display(greenTea);
            Display(coffee);
            Console.WriteLine("----------------------");

            BeverageBase americano = new Milk(new Coffee());

            Display(americano);

            BeverageBase americanoWithSugar = new Sugar(new Milk(new Coffee()));

            Display(americanoWithSugar);

            Console.ReadLine();
        }
Example #6
0
        static void Main(string[] args)
        {
            BeveragesBase coffee   = new Coffee();
            BeveragesBase blackTea = new BlackTea();
            BeveragesBase greenTea = new GreenTea();

            Console.WriteLine("Standard beverages: ");
            ShowBeverageInfo(coffee);
            ShowBeverageInfo(blackTea);
            ShowBeverageInfo(greenTea);

            BeveragesBase cappuccino           = new MilkAdd(new SugarAdd(new Coffee()));
            BeveragesBase blackTeaWithSugar    = new SugarAdd(new BlackTea());
            BeveragesBase hotChocolateWithMilk = new ChocolateAdd(new SugarAdd(new MilkAdd(new Coffee())));

            Console.WriteLine("Custom beverages: ");
            ShowBeverageInfo(cappuccino);
            ShowBeverageInfo(blackTeaWithSugar);
            ShowBeverageInfo(hotChocolateWithMilk);

            Console.ReadLine();
        }
Example #7
0
        public static DetachedCriteria ConvertOQL2NHCriteria(GreenTea.OQL.OQL oql)
        {
            DetachedCriteria dc = DetachedCriteria.For(oql.DomainObjectType);

            ProjectionList projectionList = Projections.ProjectionList();
            foreach (SelectColumn selectCol in oql.SelectColumns)
            {
                switch (selectCol.SelectOP)
                {
                    case SelectOP.Column:
                        if (string.IsNullOrEmpty(selectCol.Alias))
                        {
                            if (oql.IsDistinct && projectionList.Length == 0)
                            {
                                projectionList.Add(Projections.Distinct(Projections.Property(selectCol.PropertyName)));
                            }
                            projectionList.Add(Projections.Property(selectCol.PropertyName));
                        }
                        else
                        {
                            if (oql.IsDistinct && projectionList.Length == 0)
                            {
                                projectionList.Add(Projections.Distinct(Projections.Property(selectCol.PropertyName).As(selectCol.Alias)));
                            }
                            projectionList.Add(Projections.Property(selectCol.PropertyName).As(selectCol.Alias));
                        }
                        break;
                    case SelectOP.RowCount:
                        if (string.IsNullOrEmpty(selectCol.PropertyName))
                        {
                            projectionList.Add(Projections.RowCount());
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(selectCol.Alias))
                            {
                                if (selectCol.IsDistinct)
                                    projectionList.Add(Projections.CountDistinct(selectCol.PropertyName));
                                else
                                    projectionList.Add(Projections.Count(selectCol.PropertyName));
                            }
                            else
                            {
                                if (selectCol.IsDistinct)
                                    projectionList.Add(Projections.CountDistinct(selectCol.PropertyName).As(selectCol.Alias));
                                else
                                    projectionList.Add(Projections.Count(selectCol.PropertyName).As(selectCol.Alias));
                            }
                        }
                        break;
                    case SelectOP.Sum:
                        if (string.IsNullOrEmpty(selectCol.Alias))
                        {
                            projectionList.Add(Projections.Sum(selectCol.PropertyName));
                        }
                        else
                        {
                            projectionList.Add(Projections.Sum(selectCol.PropertyName).As(selectCol.Alias));
                        }
                        break;
                    case SelectOP.Avg:
                        if (string.IsNullOrEmpty(selectCol.Alias))
                        {
                            projectionList.Add(Projections.Avg(selectCol.PropertyName));
                        }
                        else
                        {
                            projectionList.Add(Projections.Avg(selectCol.PropertyName).As(selectCol.Alias));
                        }
                        break;
                    case SelectOP.Max:
                        if (string.IsNullOrEmpty(selectCol.Alias))
                        {
                            projectionList.Add(Projections.Max(selectCol.PropertyName));
                        }
                        else
                        {
                            projectionList.Add(Projections.Max(selectCol.PropertyName).As(selectCol.Alias));
                        }
                        break;
                    case SelectOP.Min:
                        if (string.IsNullOrEmpty(selectCol.Alias))
                        {
                            projectionList.Add(Projections.Min(selectCol.PropertyName));
                        }
                        else
                        {
                            projectionList.Add(Projections.Min(selectCol.PropertyName).As(selectCol.Alias));
                        }
                        break;
                    default:
                        break;
                }
            }

            foreach (SelectColumn groupbyCol in oql.GroupByColumns)
            {
                projectionList.Add(Projections.GroupProperty(groupbyCol.PropertyName));
            }

            if (projectionList.Length > 0)
            {
                dc.SetProjection(projectionList);
            }

            foreach (Association asso in oql.Associations)
            {
                NHibernate.SqlCommand.JoinType joinType;
                switch (asso.JoinMode)
                {
                    case JoinMode.InnerJoin:
                        joinType = NHibernate.SqlCommand.JoinType.InnerJoin;
                        break;
                    case JoinMode.LeftOuterJoin:
                        joinType = NHibernate.SqlCommand.JoinType.LeftOuterJoin;
                        break;
                    case JoinMode.RightOuterJoin:
                        joinType = NHibernate.SqlCommand.JoinType.RightOuterJoin;
                        break;
                    case JoinMode.FullJoin:
                        joinType = NHibernate.SqlCommand.JoinType.FullJoin;
                        break;
                    default:
                        joinType = NHibernate.SqlCommand.JoinType.InnerJoin;
                        break;
                }
                if (string.IsNullOrEmpty(asso.Alias))
                    dc.CreateAlias(asso.AssociationName, asso.AssociationName, joinType);
                else
                    dc.CreateAlias(asso.AssociationName, asso.Alias, joinType);
            }

            foreach (ICondition condition in oql.Conditions)
            {
                dc.Add(ConvertCondition2NHCriterion(condition));
            }

            foreach (OrderByColumn oc in oql.OrderByColumns)
            {
                switch (oc.OrderByDirect)
                {
                    case OrderByDirect.Asc:
                        dc.AddOrder(Order.Asc(oc.PropertyName));
                        break;
                    case OrderByDirect.Desc:
                        dc.AddOrder(Order.Desc(oc.PropertyName));
                        break;
                    default:
                        break;
                }
            }

            return dc;
        }
Example #8
0
 public static string TestConvert(GreenTea.OQL.OQL oql)
 {
     return ConvertOQL2NHCriteria(oql).ToString();
 }