/// <summary>
        /// Outputs the results to an appropriate file or stdout.
        /// </summary>
        /// <param name="results">The test results.</param>
        /// <param name="cla">The command line arguments.</param>
        /// <exception cref="Exception">Output format must be specified.</exception>
        public void OutputResults(ParsedData results, CommandLineArguments cla)
        {
            using (Stream s = cla.OutputFilename == null ? Console.OpenStandardOutput() : new FileStream(cla.OutputFilename, FileMode.Create))
            {
                ITestResultWriter writer = null;
                switch (cla.OutputFormat)
                {
                    case OutputFormat.CSV:
                        writer = new CSVTestResultWriter();
                        break;
                    case OutputFormat.Json:
                        writer = new JSONTestResultWriter();
                        break;
                    case OutputFormat.KVP:
                        writer = new KVPTestResultWriter();
                        break;
                    case OutputFormat.Xlsx:
                        writer = new XLSXWriter(cla.YellowBand, cla.GreenBand);
                        break;
                    default:
                        throw new Exception("Unsupported output format: " + cla.OutputFormat);
                }

                writer.WriteResults(s, results);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                var cla = new CommandLineArguments(args);
                if (cla.ErrorMessage != null)
                {
                    Console.Error.WriteLine(cla.GetUsageMessage());
                    Environment.Exit(1);
                }

                var resultsFactory = new TestResultFactory();
                var results = resultsFactory.CreateResultsFromTestFiles(cla.TestFiles);

                var outputCreator = new ParsedDataOutputter();
                outputCreator.OutputResults(results, cla);
            }
            catch (Exception ex)
            {
                // Handy to put a breakpoint here :-)
                string msg = ex.Message;
                Console.Error.WriteLine(msg);
                Console.Error.WriteLine();
                Console.Error.WriteLine(ex.StackTrace);
                Environment.Exit(1);
            }
        }