예제 #1
0
        public static Dictionary <string, string> GetCompatibilityMatrix(string productName)
        {
            Dictionary <string, string> cMatrix = new Dictionary <string, string>();
            SqlConnection sCon = new SqlConnection();

            try
            {
                sCon = SqlServer.GetConnection();
                using (sCon)
                {
                    SqlCommand command = new SqlCommand(
                        "SELECT * from Compatibility where Product='" + productName + "';",
                        sCon);
                    sCon.Open();

                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            cMatrix.Add(reader.GetName(i), reader.GetValue(i).ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerUtil.LogMessageToFile("Exception caught while Getting the compatibility matrix for product '" + productName + "' from sql server is : " + ex.ToString());
                sCon.Close();
                throw new Exception("Server Connection Error");
            }
            finally
            {
                sCon.Close();
            }
            return(cMatrix);
        }
예제 #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);
            }
        }
예제 #3
0
        public static List <Dictionary <DateTime, double> > GetLastRunResults(string productName, int dt, string userName = null)
        {
            List <Dictionary <DateTime, double> > combinedResults  = new List <Dictionary <DateTime, double> >();
            Dictionary <DateTime, double>         passedDictionary = new Dictionary <DateTime, double>();
            Dictionary <DateTime, double>         failedDictionary = new Dictionary <DateTime, double>();
            Dictionary <DateTime, double>         roiDictionary    = new Dictionary <DateTime, double>();

            string datePicked = DateTime.Now.AddDays(-dt).ToString("yyyy-MM-dd");
            string dateNow    = DateTime.Now.ToString("yyyy-MM-dd");

            using (
                var connection = SqlServer.GetConnection())
            {
                connection.Open();
                var command = connection.CreateCommand();
                if (userName == null && dateNow != datePicked)
                {
                    command.CommandText =
                        "SELECT fStartTime,fRunBy,ftcTotal,ftcExecuted,ftcPassed,ftcFailed,fRoi" +
                        " FROM [TestAutomation].[dbo].[rsmast]" +
                        " where fstartTime >= '" + datePicked + "'" +
                        " and fProductName='" + productName + "'";
                }
                else if (dateNow == datePicked && userName == null)
                {
                    command.CommandText =
                        "SELECT fStartTime,fRunBy,ftcTotal,ftcExecuted,ftcPassed,ftcFailed,fRoi" +
                        " FROM [TestAutomation].[dbo].[rsmast]" +
                        " where fstartTime >= '" + dateNow + "'" +
                        " and fProductName='" + productName + "'";
                }
                else
                {
                    command.CommandText =
                        "SELECT fStartTime,fRunBy, ftcTotal,ftcExecuted,ftcPassed,ftcFailed,fRoi" +
                        " FROM [TestAutomation].[dbo].[rsmast]" +
                        " where fstartTime >= '" + datePicked + "'" +
                        " and fProductName='" + productName + "'" +
                        " and fRunBy = '" + userName + "'";
                }

                try
                {
                    SqlDataReader sReader = command.ExecuteReader();

                    while (sReader.Read())
                    {
                        passedDictionary.Add(Convert.ToDateTime(sReader.GetValue(0)), Convert.ToDouble(sReader.GetValue(4)));
                        failedDictionary.Add(Convert.ToDateTime(sReader.GetValue(0)), Convert.ToDouble(sReader.GetValue(5)));
                        roiDictionary.Add(Convert.ToDateTime(sReader.GetValue(0)), Convert.ToDouble(sReader.GetValue(6)));
                    }

                    combinedResults.Add(passedDictionary);
                    combinedResults.Add(failedDictionary);
                    combinedResults.Add(roiDictionary);
                }
                catch (Exception exception)
                {
                    throw new ArgumentException("Invalid User", exception);
                }
                finally
                {
                    connection.Close();
                }
                return(combinedResults);
            }
        }