public void DecoratorPatternTest() { Beverage beverage = new Espresso(price: 2, description: nameof(Espresso)); Mocha mocha = new Mocha(beverage, 1, nameof(Mocha)); Assert.AreEqual(mocha.Cost(), 3); Assert.AreEqual(mocha.Description, "Espresso, Mocha"); }
private void btnTestDecoratorPattern_Click(object sender, EventArgs e) { Beverage drink1 = new HouseBlend(); // use Beverage type to hold this variable because it can be decorated. Console.WriteLine(drink1.GetDescription() + ". cost = " + drink1.cost().ToString()); drink1 = new Mocha(drink1); // converting an object1 (HouseBlend) to another object2 (Whip) by decoration. Both objects are still a Beverage. Console.WriteLine(drink1.GetDescription() + ". cost = " + drink1.cost().ToString()); }