예제 #1
0
        public static IFibonacciCalculator GetCalculator(Options options)
        {
            if (options.UseGenerator)
            {
                return new GeneratorCalculator();
            }

            return new ArrayCalculator();
        }
예제 #2
0
        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");
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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));
        }
예제 #8
0
        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));
        }
예제 #9
0
        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));
        }
예제 #10
0
        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));
        }
예제 #11
0
        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));
        }
예제 #12
0
        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));
        }