static void Main(string[] args) { #region Sandwich SandwichBase mySandwich = new VeggieSandwich(); Console.WriteLine(mySandwich.GetPrice()); Console.WriteLine(mySandwich.GetDescription()); mySandwich = new Cheese(mySandwich); Console.WriteLine(mySandwich.GetPrice()); Console.WriteLine(mySandwich.GetDescription()); mySandwich = new Olives(mySandwich); Console.WriteLine(mySandwich.GetPrice()); Console.WriteLine(mySandwich.GetDescription()); #endregion #region Pizza var pizza = new PizzaBase(); pizza = new OlivesDecorator(pizza); pizza = new MushroomsDecorator(pizza); pizza = new PepperoniDecorator(pizza); pizza = new PineappleDecorator(pizza); Console.WriteLine($"Pizza Description: {pizza.Description}"); #endregion }
public void Allow_Being_Decorated_With_Cheese() { Pizza largePizza = new LargePizza(); largePizza = new Cheese(largePizza); Assert.Equal("Large Pizza, Cheese", largePizza.GetDescription()); Assert.Equal(10.25m, largePizza.CalculateCost()); }
public static void Bake() { Pizza pizza = new LargePizza(); Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}"); pizza = new Ham(pizza); Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}"); pizza = new Cheese(pizza); Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}"); pizza = new Corn(pizza); Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}"); pizza = new Cheese(pizza); Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}"); }
public void Test() { // Arrange IPizza pizza = new LargePizza(); pizza = new Cheese(pizza); pizza = new Ham(pizza); pizza = new Cheese(pizza); // Act var description = pizza.GetDescription(); var cost = pizza.CalculateCost(); // Assert Assert.AreEqual("Large Pizza, Cheese, Ham, Cheese", description); Assert.AreEqual(12.5, cost); // Analysis Console.WriteLine(description); Console.WriteLine("{0:C2}", cost); }
public void DoWork() { //客人訂了一份土司,不需要配料,列出他的價格與描述 IBreakfast bf1 = new Toast(); Console.WriteLine("餐點:{0} 價格:{1}", bf1.GetDescription(), bf1.GetCost()); //客人訂了一份貝果,要加"雙倍"火腿,列出他的價格與描述 IBreakfast bf2 = new Bego(); bf2 = new Ham(bf2); bf2 = new Ham(bf2); Console.WriteLine("餐點:{0} 價格:{1}", bf2.GetDescription(), bf2.GetCost()); //客人訂了一份漢堡,要加牛肉 生菜 起司,列出他的價格與描述 IBreakfast bf3 = new Hamburger(); bf3 = new Beef(bf3); bf3 = new Lettuce(bf3); bf3 = new Cheese(bf3); Console.WriteLine("餐點:{0} 價格:{1}", bf3.GetDescription(), bf3.GetCost()); }