示例#1
0
        public virtual double ComputeTotalValue(List <CartLine> lines)
        {
            double price = 0;

            foreach (var item in lines)
            {
                price += MealMethods.GetMealPrice(item.Meal);
            }
            return(price);
        }
        public void GetMealPriceExtensionMethod()
        {
            meal1.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal2.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };

            double meal1Price = MealMethods.GetMealPrice(meal1);
            double meal2Price = MealMethods.GetMealPrice(meal1);

            Assert.Equal((17.85), meal1Price);
            Assert.Equal((17.85), meal2Price);
        }
        public void Has_BirthDay_Discount()
        {
            Domain.Cart target = new Domain.Cart();
            meal1.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal2.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal3.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };

            target.AddItem(meal2, DateTime.Now.DayOfWeek);
            target.AddItem(meal3, DateTime.Now.DayOfWeek);
            target.AddItem(meal1, DateTime.Now.DayOfWeek);

            var    lines = target.Lines;
            double total = target.ComputeTotalValue(lines);

            Assert.Equal((17.85 * 3), total);

            Domain.Client client = new Domain.Client()
            {
                FirstName = "Tester",
                LastName  = "Test",
                Birthday  = DateTime.Now.Date,
                Email     = "*****@*****.**"
            };

            bool sameDate = target.MealOnBirthDay(client.Birthday);

            Assert.True(sameDate);

            if (sameDate)
            {
                total -= MealMethods.GetMealPrice(meal1);
            }

            Assert.Equal(35.7, total);
        }