예제 #1
0
        static TestReportBase ReadInputInternal(string path, ref ExitCode.ExitCodeData errorCode)
        {
            string xmlReportFile = path;

            if (!File.Exists(xmlReportFile))
            {
                // the input path could be a folder, try to detect it
                string dir = xmlReportFile;
                xmlReportFile = Path.Combine(dir, XMLReport_File);
                if (!File.Exists(xmlReportFile))
                {
                    // still not find, may be under "Report" sub folder? try it
                    xmlReportFile = Path.Combine(dir, XMLReport_SubDir_Report, XMLReport_File);
                    if (!File.Exists(xmlReportFile))
                    {
                        OutputWriter.WriteLine(Properties.Resources.ErrMsg_CannotFindXmlReportFile + " " + path);
                        errorCode = ExitCode.FileNotFound;
                        return(null);
                    }
                }
            }

            // load XML from file with the specified XML schema
            ResultsType root = XmlReportUtilities.LoadXmlFileBySchemaType <ResultsType>(xmlReportFile);

            if (root == null)
            {
                errorCode = ExitCode.CannotReadFile;
                return(null);
            }

            // try to load the XML data as a GUI test report
            GUITestReport guiReport = new GUITestReport(root, xmlReportFile);

            if (guiReport.TryParse())
            {
                return(guiReport);
            }

            // try to load as API test report
            APITestReport apiReport = new APITestReport(root, xmlReportFile);

            if (apiReport.TryParse())
            {
                return(apiReport);
            }

            // try to load as BP test report
            BPTReport bptReport = new BPTReport(root, xmlReportFile);

            if (bptReport.TryParse())
            {
                return(bptReport);
            }

            OutputWriter.WriteLine(Properties.Resources.ErrMsg_Input_InvalidFirstReportNode + " " + path);
            errorCode = ExitCode.InvalidInput;
            return(null);
        }
예제 #2
0
        public static void Exit(ExitCode.ExitCodeData ecd, bool writeCommandUsage = false)
        {
            if (!string.IsNullOrWhiteSpace(ecd.Message))
            {
                OutputWriter.WriteLines(ecd.Message);
            }

            if (writeCommandUsage)
            {
                OutputWriter.WriteLine();
                OutputWriter.WriteCommandUsage();
            }

            Environment.Exit(ecd.Code);
        }
예제 #3
0
        static void Convert(CommandArguments args)
        {
            // input
            IEnumerable <TestReportBase> testReports = ReadInput(args);

            // output - none
            if (args.OutputFormats == OutputFormats.None)
            {
                ProgramExit.Exit(ExitCode.UnknownOutputFormat, true);
                return;
            }

            // output - junit
            if ((args.OutputFormats & OutputFormats.JUnit) == OutputFormats.JUnit)
            {
                // the output JUnit path must be NOT an exist directory
                if (Directory.Exists(args.JUnitXmlFile))
                {
                    OutputWriter.WriteLine(Properties.Resources.ErrMsg_JUnit_OutputCannotDir);
                    ProgramExit.Exit(ExitCode.InvalidArgument);
                    return;
                }

                // if not an aggregation report output, then only convert for the first report
                if (!args.Aggregation)
                {
                    TestReportBase testReport = testReports.First();
                    if (testReport == null)
                    {
                        ProgramExit.Exit(ExitCode.CannotReadFile);
                        return;
                    }

                    // the output JUnit file path must be NOT same as the input file
                    FileInfo fiInput  = new FileInfo(testReport.ReportFile);
                    FileInfo fiOutput = new FileInfo(args.JUnitXmlFile);
                    if (fiInput.FullName == fiOutput.FullName)
                    {
                        OutputWriter.WriteLine(Properties.Resources.ErrMsg_JUnit_OutputSameAsInput);
                        ProgramExit.Exit(ExitCode.InvalidArgument);
                        return;
                    }

                    // convert
                    if (!JUnit.Converter.ConvertAndSave(args, testReport))
                    {
                        ProgramExit.Exit(ExitCode.GeneralError);
                    }
                    else
                    {
                        OutputWriter.WriteLine(Properties.Resources.InfoMsg_JUnit_OutputGenerated, fiOutput.FullName);
                    }
                }
                else
                {
                    // an aggregation report output
                    if (!JUnit.Converter.ConvertAndSaveAggregation(args, testReports))
                    {
                        ProgramExit.Exit(ExitCode.GeneralError);
                    }
                    else
                    {
                        FileInfo fiOutput = new FileInfo(args.JUnitXmlFile);
                        OutputWriter.WriteLine(Properties.Resources.InfoMsg_JUnit_OutputGenerated, fiOutput.FullName);
                    }
                }
            }

            // output - nunit 3
            if ((args.OutputFormats & OutputFormats.NUnit3) == OutputFormats.NUnit3)
            {
            }
        }