static void Main(string[] args) { // create message writer service var messageWriterService = new MessageWriterService(); // write message (letting service use the default writer, which is specified in app.config) messageWriterService.WriteMessage("Hello World"); // write press to exit message Console.WriteLine("\npress any key to exit..."); // wait for user keypress before closing Console.ReadKey(); }
public void TestConsoleMessageWriterOutput() { // set test text var testText = "Hello World Console"; // redirect the console output into a stringbuilder StringBuilder builder = new StringBuilder(); TextWriter writer = new StringWriter(builder); Console.SetOut(writer); // get message writer service var svc = new MessageWriterService(); // write message, passing a specific IMessageWriter bool success = svc.WriteMessage(testText, new MessageWriters.ConsoleMessageWriter()); // read the redirected console output to determine if it wrote correctly Assert.AreEqual(testText, builder.ToString()); // make sure true was returned (and that a caught/logged exception didn't happen) Assert.AreEqual(success, true); }