public static List <string> GetBuildsList(string productName)
        {
            Hashtable productConfigurationHashtable = ProductConfiguration.GetProductConfigurationHashtable(productName);
            var       buildLocation = productConfigurationHashtable["DropLocation"].ToString();

            if (Directory.Exists(buildLocation))
            {
                string[] list = Directory.GetDirectories(buildLocation);
                return(list.ToList());
            }
            return(null);
        }
Exemple #2
0
        public static void UpdateResults(string productName, string productBuildNumber, string testBuildNumber,
                                         DateTime starttime, DateTime endtime)
        {
            string source = ConfigurationManager.AppSettings["TrxFileLocation"];

            LogMessageToFile("The source path for GetShortResults is : " + source);
            source = GetLatestResultspath(source);
            if (!File.Exists(source))
            {
            }
            else
            {
                LogMessageToFile("Trying to load the source");
                XDocument xDoc = XDocument.Load(source);
                LogMessageToFile("Source loaded");
                XNamespace defaultNs = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010";

                var dataHashtable = new Hashtable();
                var testRunNode   = (from data in xDoc.Descendants(defaultNs + "TestRun")
                                     select data).ToList();
                var masterRecordSet1 = (from src in testRunNode
                                        select new
                {
                    testRunId = src.Attribute("id").Value,
                    testRunName = src.Attribute("name").Value,
                    testRunUser = src.Attribute("runUser").Value
                });
                foreach (var record in masterRecordSet1)
                {
                    dataHashtable.Add("ID", record.testRunId);
                    dataHashtable.Add("FMASTRUNID", record.testRunName);
                    dataHashtable.Add("FRUNUSER", record.testRunUser);
                }
                var resultSummaryNode = (from data in xDoc.Descendants(defaultNs + "ResultSummary")
                                         select data).ToList();
                var resultSummaryRecordSet1 = (from src in resultSummaryNode
                                               select new
                {
                    outcome = src.Attribute("outcome").Value
                });
                foreach (var record in resultSummaryRecordSet1)
                {
                    dataHashtable.Add("FOUTCOME", record.outcome);
                }
                resultSummaryNode = (from data in xDoc.Descendants(defaultNs + "ResultSummary")
                                     select data).Descendants(defaultNs + "Counters").ToList();
                var resultSummaryRecordSet2 = (from src in resultSummaryNode
                                               select new
                {
                    totalTestCases = src.Attribute("total").Value,
                    totalTestCasesExecuted = src.Attribute("executed").Value,
                    totalTestCasesPassed = src.Attribute("passed").Value,
                    totalTestCasesError = src.Attribute("error").Value,
                    totalTestCasesFailed = src.Attribute("failed").Value,
                    totalTestCasesTimeout = src.Attribute("timeout").Value,
                    totalTestCasesAborted = src.Attribute("aborted").Value,
                    totalTestCasesInconclusive = src.Attribute("inconclusive").Value
                });
                foreach (var record in resultSummaryRecordSet2)
                {
                    dataHashtable.Add("FTCTOTAL", record.totalTestCases);
                    dataHashtable.Add("FTCEXECUTED", record.totalTestCasesExecuted);
                    dataHashtable.Add("FTCPASSED", record.totalTestCasesPassed);
                    dataHashtable.Add("FTCERROR", record.totalTestCasesError);
                    dataHashtable.Add("FTCFAILED", record.totalTestCasesFailed);
                    dataHashtable.Add("FTCTIMEOUT", record.totalTestCasesTimeout);
                    dataHashtable.Add("FTCABORTED", record.totalTestCasesAborted);
                    dataHashtable.Add("FTCINCONCLUSIVE", record.totalTestCasesInconclusive);
                }
                using (var connection = SqlServer.GetConnection())
                {
                    connection.Open();
                    var    command   = connection.CreateCommand();
                    double roiFactor = ProductConfiguration.GetProductRoiFactor(productName);
                    var    roi       = Convert.ToDouble(dataHashtable["FTCPASSED"]) * roiFactor;
                    command.CommandText =
                        "INSERT INTO rsmast (fMasterRunId, fProductName, fProductBuildNumber, fTestBuildNumber, fOutCome, fRunBy, fStartTime, fEndTime, ftcTotal, ftcExecuted, ftcPassed, ftcFailed, ftcTimeout, ftcAborted, ftcError, ftcInconclusive, ftcUrl, ftcbrowser, ftcExePath, fRoi)" +
                        "VALUES ('" +
                        dataHashtable["FMASTRUNID"] + "','" +
                        productName + "','" +
                        productBuildNumber + "','" +
                        testBuildNumber + "','" +
                        dataHashtable["FOUTCOME"] + "','" +
                        dataHashtable["FRUNUSER"] + "','" +
                        starttime + "','" +
                        endtime + "','" +
                        dataHashtable["FTCTOTAL"] + "','" +
                        dataHashtable["FTCEXECUTED"] + "','" +

                        dataHashtable["FTCPASSED"] + "','" +
                        dataHashtable["FTCFAILED"] + "','" +

                        dataHashtable["FTCTIMEOUT"] + "','" +
                        dataHashtable["FTCABORTED"] + "','" +
                        dataHashtable["FTCERROR"] + "','" +
                        dataHashtable["FTCINCONCLUSIVE"] + "','" +
                        "url" + "','" +
                        "browser" + "','" +
                        "exepath" + "','" +
                        roi + "');";

                    try
                    {
                        command.ExecuteNonQuery();
                        connection.Close();
                        LogMessageToFile("Updating results to SQL was successfully completed.");
                    }
                    catch (Exception ex)
                    {
                        LogMessageToFile("Exception caught while updating results to SQL Server is : " + ex.ToString());
                        throw new Exception("failed to update rsmast table");
                    }
                }

                var detailedTestRunNode = (from data in xDoc.Descendants(defaultNs + "Results")
                                           select data).Descendants(defaultNs + "UnitTestResult").ToList();

                var detailedTestrecordSet1 = (from src in detailedTestRunNode
                                              select new
                {
                    TestRunID = src.Attribute("testId").Value,
                    testcaseRunId = src.Attribute("testId").Value,
                    TestName = src.Attribute("testName").Value,
                    TestOutcome = src.Attribute("outcome").Value,
                    EnvirnomentName = src.Attribute("computerName").Value,
                    //Duration = src.Attribute("duration").Value,
                    StartTime = src.Attribute("startTime").Value,
                    EndTime = src.Attribute("endTime").Value,
                    Message = src
                              .Descendants(defaultNs + "Output")
                              .Descendants(defaultNs + "ErrorInfo")
                              .Descendants(defaultNs + "Message"),
                    StackTrace = src
                                 .Descendants(defaultNs + "Output")
                                 .Descendants(defaultNs + "ErrorInfo")
                                 .Descendants(defaultNs + "StackTrace")
                });

                foreach (var record in detailedTestrecordSet1)
                {
                    using (var connection = SqlServer.GetConnection())
                    {
                        connection.Open();
                        var command0 = connection.CreateCommand();
                        command0.CommandText = "select fOutCome from rsitem where fMasterRunId='" +
                                               dataHashtable["FMASTRUNID"] +
                                               "' and  fTestRunId='" + record.TestRunID + "'";
                        string result = null;
                        try
                        {
                            result = command0.ExecuteScalar().ToString();
                        }
                        catch (NullReferenceException)
                        {
                            var command1 = connection.CreateCommand();
                            command1.CommandText =
                                "INSERT INTO rsitem (fMasterRunId, fTestRunId, fOutCome)" +
                                "VALUES ('" +
                                dataHashtable["FMASTRUNID"] + "','" +
                                record.TestRunID + "','" +
                                record.TestOutcome + "');";
                            try
                            {
                                command1.ExecuteNonQuery();
                            }
                            catch (Exception)
                            {
                                throw new Exception("Failed to update rsitem table");
                            }
                        }
                        if (result != null &&
                            (result.ToUpper() != "Failed".ToUpper() && record.TestOutcome.ToUpper() == "Failed".ToUpper()))
                        {
                            var command2 = connection.CreateCommand();
                            command2.CommandText =
                                "update rsitem set fOutCome = 'Failed' where fMasterRunId='" +
                                dataHashtable["FMASTRUNID"] + "' and fTestRunId='" + record.TestRunID + "'";
                        }
                        var command3 = connection.CreateCommand();
                        command3.CommandText = "update rsmast set fMachineName = '" + record.EnvirnomentName +
                                               "' where fMasterRunId='" +
                                               dataHashtable["FMASTRUNID"] + "'";
                        try
                        {
                            command3.ExecuteNonQuery();
                        }
                        catch (Exception)
                        {
                            throw new Exception("Failed to update fMachineName in rsmast table");
                        }
                        var duration = Convert.ToDateTime(record.EndTime) - Convert.ToDateTime(record.StartTime);
                        var command  = connection.CreateCommand();
                        command.CommandText =
                            "INSERT INTO rsdetailtestview (fMasterRunId, fTestRunId, ftcName, ftcComputerName, ftcDuration, ftcStartTime, ftcEndTime, ftcOutcome, ftcDebugTrace, ftcStackTrace)" +
                            "VALUES ('" +
                            dataHashtable["FMASTRUNID"] + "','" +
                            record.TestRunID + "','" +
                            record.TestName + "','" +
                            record.EnvirnomentName + "','" +
                            duration.TotalMinutes + "','" +
                            record.StartTime + "','" +
                            record.EndTime + "','" +
                            record.TestOutcome + "','" +
                            record.Message + "','" +
                            record.StackTrace + "');";
                        try
                        {
                            command.ExecuteNonQuery();
                            LogMessageToFile("Updating results to SQL was successfully completed.");
                        }
                        catch (Exception ex)
                        {
                            LogMessageToFile("Exception caught while updating results to SQL Server is : " + ex.ToString());
                            throw new Exception("Failed to update rsdetailtestview table");
                        }
                        connection.Close();
                    }
                }

                LogMessageToFile("Updating Splog");
                SplogUtils spUtils = new SplogUtils();
                spUtils.splogPathLocal = LoggerUtil.GetTempPath();
                spUtils.splogfileName  = productName + "_" + dataHashtable["FMASTRUNID"].ToString().Replace("-", "_").Replace(":", "_") + ".splog";
                LogMessageToFile("Splog file name is : " + spUtils.splogfileName);
                spUtils.CreateXMLFile(productName, testBuildNumber);
                LogMessageToFile("Created Splog file");
                spUtils.Generate(dataHashtable, productName, productBuildNumber, testBuildNumber, "", "");
                LogMessageToFile("Generated splog for the current run");
                spUtils.ReportToSplunk(productName, testBuildNumber);
            }
        }
 public static List <string> GetProductList()
 {
     return(ProductConfiguration.GetProductList());
 }