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()); }
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()); }