public void test_component_demo() { ConcreteComponentA componentA = new ConcreteComponentA(); ConcreteComponentB componentB = new ConcreteComponentB(); ConcreteDecoratorA decoratorA = new ConcreteDecoratorA(componentA); decoratorA.Operation(); decoratorA.SetComponent(componentB); decoratorA.Operation(); }
static bool TestDecoratorPattern() { Console.WriteLine("TESTING THE DECORATOR DESIGN PATTERN: "); ConcreteComponent comp = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(comp); ConcreteDecoratorB d2 = new ConcreteDecoratorB(d1); comp.Operation(); //Output: //Operation from ConcreteComponent d1.Operation(); //Output: //Operation from ConcreteComponent //(AddedBehaviour A) + Operation from ConcreteDecoratorA d2.Operation(); //Output: //Operation from ConcreteComponent //(AddedBehaviour A) + Operation from ConcreteDecoratorA //(AddedBehaviour B) + Operation from ConcreteDecoratorB return(true); }
public void AddStateTest() { Component component = new ConcreteComponent(); component = new ConcreteDecoratorA(component); Assert.That((component as ConcreteDecoratorA)?.AddedState == "added state"); Assert.That(() => component.Operation(), Throws.Exception.With.Message.EqualTo("Operation from object of ConcreteComponent type")); }
public static void TestDecorator() { IComponent component = new ConcreteComponent(); Console.WriteLine(component.Operation()); Decorator decorator = new ConcreteDecoratorA(component); Console.WriteLine(decorator.Operation()); decorator = new ConcreteDecoratorB(decorator); Console.WriteLine(decorator.Operation()); }
public static void test() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent("c"); Decorator a1 = new ConcreteDecoratorA("a1"); Decorator b1 = new ConcreteDecoratorA("b1"); Decorator a2 = new ConcreteDecoratorA("a2"); // Link decorators a1.SetComponent(c); b1.SetComponent(a1); a2.SetComponent(b1); a2.Operation(); }
public static void Main() { ConcreteComponent cc = new ConcreteComponent(); cc.Operation(); Console.WriteLine(); ConcreteDecoratorA cd1 = new ConcreteDecoratorA(cc); cd1.Operation(); Console.WriteLine(); ConcreteDecoratorB cd2 = new ConcreteDecoratorB(cd1); cd2.Operation(); Console.WriteLine(); Console.ReadKey(); }