Beispiel #1
0
        static int SaveReport(string filePath, string nunitTestSetName, string enviroment = null)
        {
            Log.Info("saving final report in " + filePath + "...");
            string rootDir = Path.GetDirectoryName(filePath);
            string date    = DateTime.Now.ToShortDateString();
            string time    = DateTime.Now.ToLongTimeString();

            int failures = 0;
            int total    = 0;
            int notRun   = 0;

            foreach (var item in runInfos.Keys)
            {
                RunInfo runInfo = runInfos[item];
                failures += runInfo.Failures;
                notRun   += runInfo.Not_run;
                total    += runInfo.Total;
            }
            XElement root = new XElement("test-results", new XAttribute("name", nunitTestSetName),
                                         new XAttribute("failures", failures.ToString()),
                                         new XAttribute("total", total.ToString()),
                                         new XAttribute("not-run", notRun.ToString()),
                                         new XAttribute("date", date),
                                         new XAttribute("time", time));

            if (enviroment != null)   // todo

            {
            }
            //root.Add("culture-info", new XAttribute("current-culture", "en-US"),  new XAttribute("current-uiculture", "en-US") ); // todo
            XDocument resultDoc = new XDocument();

            //XElement tmp = resultDoc.Element("results");
            foreach (var key in infos.Keys)
            {
                //string suiteNameRoot = rootDir + "\\" + key + ".dll";
                root.Add(InfoToXml(key));
            }
            resultDoc.Add(root);

            resultDoc.Save("tmpReport" /*, SaveOptions.None*/);
            File.Copy("tmpReport", filePath);
            File.OpenRead(filePath).Close();
            Console.WriteLine("saved");
            return(failures);
        }
Beispiel #2
0
        static bool ProcessFile(string targetFilePath, string sourceFilePath)
        {
            string outFileName = targetFilePath;
            if (!infos.ContainsKey(outFileName))
                infos.Add(outFileName, new Info("root"));
            bool orgReport = false;
            if (!runInfos.ContainsKey(outFileName)) {
                RunInfo ri = new RunInfo();
                runInfos.Add(outFileName, ri);
            }
            var filesToGlue = new[] { sourceFilePath };
            foreach (var item in filesToGlue) {
                Log.Info("glue " + item);

                XDocument xml = XDocument.Load(item);
                XElement tmpEl = xml.Root;
                var total = int.Parse(tmpEl.Attribute("total").Value);
                var not_run = int.Parse(tmpEl.Attribute("not-run").Value);
                var failures = int.Parse(tmpEl.Attribute("failures").Value);
                runInfos[outFileName].Plus(total, failures, not_run);
                //infos[outFilePath] = new Info();
                IEnumerable<XElement> elements;

                if (orgReport)
                    elements = xml.Root.Elements("test-suite");
                else
                    elements = xml.Root.Element("test-suite").Element("results").Elements("test-suite");
                foreach (XElement main in elements) {
                    Info resultInfo;
                    string rootSuiteName = main.Attribute("name").Value;
                    if (infos[outFileName].DescendantDict.ContainsKey(rootSuiteName)) {
                        resultInfo = ParseDescendantsRecursive(main, infos[outFileName].DescendantDict[rootSuiteName]);
                        infos[outFileName].DescendantDict[rootSuiteName] = resultInfo;
                    }
                    else {
                        resultInfo = ParseDescendantsRecursive(main, null);
                        infos[outFileName].DescendantDict.Add(rootSuiteName, resultInfo);
                    }
                    Log.Info(rootSuiteName);
                }
            }
            foreach (var subRootInfo in infos[outFileName].DescendantDict.Values) {
                infos[outFileName].Success = infos[outFileName].Success && subRootInfo.Success;
            }
            return infos[outFileName].Success;
        }
Beispiel #3
0
        static bool ProcessFile(string targetFilePath, string sourceFilePath)
        {
            string outFileName = targetFilePath;

            if (!infos.ContainsKey(outFileName))
            {
                infos.Add(outFileName, new Info("root"));
            }
            bool orgReport = false;

            if (!runInfos.ContainsKey(outFileName))
            {
                RunInfo ri = new RunInfo();
                runInfos.Add(outFileName, ri);
            }
            var filesToGlue = new[] { sourceFilePath };

            foreach (var item in filesToGlue)
            {
                Log.Info("glue " + item);

                XDocument xml      = XDocument.Load(item);
                XElement  tmpEl    = xml.Root;
                var       total    = int.Parse(tmpEl.Attribute("total").Value);
                var       not_run  = int.Parse(tmpEl.Attribute("not-run").Value);
                var       failures = int.Parse(tmpEl.Attribute("failures").Value);
                runInfos[outFileName].Plus(total, failures, not_run);
                //infos[outFilePath] = new Info();
                IEnumerable <XElement> elements;

                if (orgReport)
                {
                    elements = xml.Root.Elements("test-suite");
                }
                else
                {
                    elements = xml.Root.Element("test-suite").Element("results").Elements("test-suite");
                }
                foreach (XElement main in elements)
                {
                    Info   resultInfo;
                    string rootSuiteName = main.Attribute("name").Value;
                    if (infos[outFileName].DescendantDict.ContainsKey(rootSuiteName))
                    {
                        resultInfo = ParseDescendantsRecursive(main, infos[outFileName].DescendantDict[rootSuiteName]);
                        infos[outFileName].DescendantDict[rootSuiteName] = resultInfo;
                    }
                    else
                    {
                        resultInfo = ParseDescendantsRecursive(main, null);
                        infos[outFileName].DescendantDict.Add(rootSuiteName, resultInfo);
                    }
                    Log.Info(rootSuiteName);
                }
            }
            foreach (var subRootInfo in infos[outFileName].DescendantDict.Values)
            {
                infos[outFileName].Success = infos[outFileName].Success && subRootInfo.Success;
            }
            return(infos[outFileName].Success);
        }