Ejemplo n.º 1
0
        public void Ex6()
        {
            string input     = "----Lorem     ipsum   dolor sit---";
            var    component = new ConcreteComponent();
            var    decorator = new AddParagraph(new RemoveDoubleSpaces(new RemoveDashesAtEdges(component)));
            string result    = decorator.Transform(input);

            Assert.AreEqual("<p>Lorem ipsum dolor sit</p>", result);
        }
Ejemplo n.º 2
0
        public void Ex3()
        {
            string input     = "----Lorem     ipsum   dolor sit---";
            var    component = new ConcreteComponent();
            var    decorator = new AddParagraph(component);
            string result    = decorator.Transform(input);

            Assert.AreEqual("<p>----Lorem     ipsum   dolor sit---</p>", result);
        }
Ejemplo n.º 3
0
        public void Ex2()
        {
            string input     = "----Lorem     ipsum   dolor sit---";
            var    component = new ConcreteComponent();
            var    decorator = new RemoveDoubleSpaces(component);
            string result    = decorator.Transform(input);

            Assert.AreEqual("----Lorem ipsum dolor sit---", result);
        }
Ejemplo n.º 4
0
        public void Ex5()
        {
            // Same as Ex4 but different order of transformations
            string input     = "----Lorem     ipsum   dolor sit---";
            var    component = new ConcreteComponent();
            var    decorator = new RemoveDashesAtEdges(new AddParagraph(component));
            string result    = decorator.Transform(input);

            Assert.AreEqual("<p>----Lorem     ipsum   dolor sit---</p>", result);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Component component  = new ConcreteComponent();  //man
            Decorator decoratorA = new ConcreteDecoratorA(); //man in suit
            Decorator decoratorB = new ConcreteDecoratorB(); //man in suit in car

            component.Operation();
            decoratorA.Component = component;
            decoratorA.Operation();

            decoratorB.Component = decoratorA;
            decoratorB.Operation();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Client client = new Client();

            var simple = new ConcreteComponent();

            Console.WriteLine("Client: I get a simple component:");
            client.ClientCode(simple);
            Console.WriteLine();

            // ...as well as decorated ones.
            //
            // Note how decorators can wrap not only simple components but the
            // other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            Console.WriteLine("Client: Now I've got a decorated component:");
            client.ClientCode(decorator2);
        }
Ejemplo n.º 7
0
        public Client()
        {
            Program program = new Program();

            var simple = new ConcreteComponent();

            Console.WriteLine("Program: I get a simple component:");
            program.ProgramCode(simple);
            Console.WriteLine();

            // ...as well as decorated ones.
            //
            // Note how decorators can wrap not only simple components but the
            // other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            Console.WriteLine("Program: Now I've got a decorated component:");
            program.ProgramCode(decorator2);
        }
Ejemplo n.º 8
0
        public void Ex1()
        {
            Client client = new Client();

            var simple = new ConcreteComponent();

            // Client: I get a simple component
            client.ClientCode(simple);
            Assert.AreEqual("RESULT: ConcreteComponent", _log.Dequeue());

            // ...as well as decorated ones.
            //
            // Note how decorators can wrap not only simple components but the
            // other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            // Client: Now I've got a decorated component
            client.ClientCode(decorator2);
            Assert.AreEqual("RESULT: ConcreteDecoratorB(ConcreteDecoratorA(ConcreteComponent))", _log.Dequeue());

            Assert.AreEqual(0, _log.Count);
        }