Exemplo n.º 1
0
        public void PrintLineHello()
        {
            ICommand     command = new PrintLineCommand(new ConstantExpression("Hello"));
            StringWriter writer  = new StringWriter();

            lock (System.Console.Out)
            {
                TextWriter originalWriter = System.Console.Out;
                System.Console.SetOut(writer);

                command.Execute(null, null);

                System.Console.SetOut(originalWriter);
            }

            Assert.AreEqual("Hello\r\n", writer.ToString());
        }
Exemplo n.º 2
0
        public void PrintHelloWorldUsingCompositeCommand()
        {
            ICommand         firstCommand  = new PrintCommand(new ConstantExpression("Hello "));
            ICommand         secondCommand = new PrintLineCommand(new ConstantExpression("World"));
            CompositeCommand command       = new CompositeCommand();

            command.AddCommand(firstCommand);
            command.AddCommand(secondCommand);

            StringWriter writer = new StringWriter();

            lock (System.Console.Out)
            {
                TextWriter originalWriter = System.Console.Out;
                System.Console.SetOut(writer);

                command.Execute(null, null);

                System.Console.SetOut(originalWriter);
            }

            Assert.AreEqual("Hello World\r\n", writer.ToString());
        }