public void SayHelloTest() { IHelloWorldGenerator generator = null; try { IMessagePrinter printer = MessagePrinterFactory.GetMessagePrinterInstance(PrinterType.Console); generator = HelloWorldGeneratorFactory.GetHelloWorldGeneratorInstance(GeneratorType.Console, printer); } catch (Exception ex) { Assert.Fail(ex.Message); } Assert.IsTrue(generator != null, "Failed to create HelloWorldGenerator for {0} type.", GeneratorType.Console); Assert.IsTrue(generator.SayHello(), "Can't Say Hello World! Something went wrong!"); try { IMessagePrinter printer = MessagePrinterFactory.GetMessagePrinterInstance(PrinterType.Console); generator = HelloWorldGeneratorFactory.GetHelloWorldGeneratorInstance(GeneratorType.Mobile, printer); } catch (Exception ex) { if (!(ex is NotImplementedException)) { Assert.Fail(ex.Message); } } }
static void Main(string[] args) { PrinterType printerType = PrinterType.Console; if (args.Length > 0) { printerType = (PrinterType)Enum.Parse(typeof(PrinterType), args[0], true); } IMessagePrinter printer = MessagePrinterFactory.GetMessagePrinterInstance(printerType); IHelloWorldGenerator generator = HelloWorldGeneratorFactory.GetHelloWorldGeneratorInstance(GeneratorType.Console, printer); if (generator != null) { generator.SayHello(); } }