public static IFibonacciCalculator GetCalculator(Options options) { if (options.UseGenerator) { return new GeneratorCalculator(); } return new ArrayCalculator(); }
public static Options ParseOptions(string[] args) { var options = new Options(); CommandLine.Parser.Default.ParseArgumentsStrict(args, options); if (options.InputNumber > 0 || !string.IsNullOrWhiteSpace(options.InputFile) || options.UseInteractiveMode()) { return options; } Console.Error.Write(CommandLine.Text.HelpText.AutoBuild(options)); throw new ArgumentException("Invalid paramater set", "args"); }
public void calculator_defaults_to_array_calculator() { //Arrange var options = new Options() { InputNumber = 23 }; //Act var handler = Program.GetCalculator(options); //Assert Assert.IsInstanceOfType(handler, typeof(ArrayCalculator)); }
public void generator_flag_uses_generator_calculator() { //Arrange var options = new Options() { InputNumber = 23, UseGenerator = true }; //Act var handler = Program.GetCalculator(options); //Assert Assert.IsInstanceOfType(handler, typeof(GeneratorCalculator)); }
public static IOutputHandler GetOutputHandler(Options options) { IOutputHandler result = new ConsoleIOHandler(); if (string.IsNullOrWhiteSpace(options.OutputFile)) { return result; } switch (options.OutputFileType) { default: case Options.FileType.PlainText: return new TextFileIOHandler(options.OutputFile); case Options.FileType.Xml: return new XmlIOHandler(options.OutputFile); } }
public static IInputHandler GetInputHandler(Options options) { if (options.UseInteractiveMode()) { return new ConsoleIOHandler(); } if (options.InputNumber > 0) { return new GenericIOHandler { InputHandler = () => options.InputNumber }; } switch (options.InputFileType) { default: case Options.FileType.Undefined: case Options.FileType.PlainText: return new TextFileIOHandler(options.InputFile); case Options.FileType.Xml: return new XmlIOHandler(options.InputFile); } }
public void interactive_and_direct_input_uses_direct_input() { //Arrange var options = new Options() { InteractiveMode = true, InputNumber = 23 }; //Act var handler = Program.GetInputHandler(options); //Assert Assert.IsInstanceOfType(handler, typeof(GenericIOHandler)); }
public void xml_file_input_uses_xml_input() { //Arrange var options = new Options() { InteractiveMode = true, InputNumber = 23, InputFile = "input.xml" }; //Act var handler = Program.GetInputHandler(options); //Assert Assert.IsInstanceOfType(handler, typeof(GenericIOHandler)); }
public void output_with_xml_users_xml_handler() { //Arrange var options = new Options() { InputNumber = 23, OutputFile = "file.xml" }; //Act var handler = Program.GetOutputHandler(options); //Assert Assert.IsInstanceOfType(handler, typeof(XmlIOHandler)); }
public void output_defaults_to_console() { //Arrange var options = new Options() { InputNumber = 23, }; //Act var handler = Program.GetOutputHandler(options); //Assert Assert.IsInstanceOfType(handler, typeof(ConsoleIOHandler)); }
public void interactive_uses_console_handler_input() { //Arrange var options = new Options() { InteractiveMode = true }; //Act var handler = Program.GetInputHandler(options); //Assert Assert.IsInstanceOfType(handler, typeof(ConsoleIOHandler)); }
public void interactive_and_input_file_uses_file_handler_input() { //Arrange var options = new Options() { InteractiveMode = true, InputFile = "input.txt" }; //Act var handler = Program.GetInputHandler(options); //Assert Assert.IsInstanceOfType(handler, typeof(TextFileIOHandler)); }