Example #1
0
        static IEnumerable <TestReportBase> ReadInput(CommandArguments args)
        {
            if (string.IsNullOrWhiteSpace(args.InputPath))
            {
                ProgramExit.Exit(ExitCode.InvalidInput, true);
                yield break;
            }

            ExitCode.ExitCodeData errorCode = ExitCode.Success;
            bool anyFailures = false;

            foreach (string path in args.AllPositionalArgs)
            {
                TestReportBase testReport = ReadInputInternal(path, ref errorCode);
                if (testReport != null)
                {
                    yield return(testReport);
                }
                else
                {
                    anyFailures = true;
                }
            }

            if (anyFailures && args.AllPositionalArgs.Count == 1)
            {
                // only one test report and it failed to read, exit
                ProgramExit.Exit(errorCode);
                yield break;
            }
        }
Example #2
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);
        }
Example #3
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);
        }