Ejemplo n.º 1
0
        public void SaveToDatabase(TestClass tc, MethodInfoEx mi, Exception err = null)
        {
            using (TestingEntities entities = TestEntitiesConnection.CreateEntities())
            {
                List <Session> rgSessions = entities.Sessions.Where(p => p.Session1 == m_strName).ToList();

                if (rgSessions.Count > 0)
                {
                    int         nSessionID = rgSessions[0].ID;
                    List <Test> rgTest     = entities.Tests.Where(p => p.SessionID == nSessionID && p.TestGroup == tc.Name && p.TestMethod == mi.Name).ToList();

                    if (rgTest.Count > 0)
                    {
                        if (err != null)
                        {
                            rgTest[0].ErrorString   = getString(err.Message, 1023);
                            rgTest[0].ErrorLocation = getString(err.StackTrace, 1023);
                        }

                        rgTest[0].Success = (mi.Status == MethodInfoEx.STATUS.Passed) ? true : false;
                        decimal dTiming = Math.Min(9999999, (decimal)mi.TestTiming.TotalMilliseconds);
                        rgTest[0].TestTiming = dTiming;

                        entities.SaveChanges();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadFromDatabase()
        {
            using (TestingEntities entities = TestEntitiesConnection.CreateEntities())
            {
                List <Session> rgSessions = entities.Sessions.Where(p => p.Session1 == m_strName && p.Path == m_strPath).OrderByDescending(p => p.TimeStamp).Take(1).ToList();

                if (rgSessions.Count > 0)
                {
                    int         nSessionID = rgSessions[0].ID;
                    List <Test> rgTests    = entities.Tests.Where(p => p.SessionID == nSessionID).ToList();

                    if (rgTests.Count > 0)
                    {
                        foreach (TestClass tc in m_rgClasses)
                        {
                            List <Test> rgTests0 = rgTests.Where(p => p.TestGroup == tc.Name).ToList();

                            if (rgTests0.Count > 0)
                            {
                                foreach (MethodInfoEx mi in tc.Methods)
                                {
                                    List <Test> rgTests1 = rgTests0.Where(p => p.TestMethod.ToLower() == mi.Name.ToLower()).ToList();

                                    if (rgTests1.Count > 0)
                                    {
                                        if (rgTests1[0].Success.GetValueOrDefault())
                                        {
                                            mi.Status = MethodInfoEx.STATUS.Passed;
                                        }
                                        else if (rgTests1[0].ErrorString.Length > 0)
                                        {
                                            mi.Status = MethodInfoEx.STATUS.Failed;
                                            mi.ErrorInfo.SetErrors(rgTests1[0].ErrorString, rgTests1[0].ErrorLocation);
                                        }
                                        else
                                        {
                                            mi.Status = MethodInfoEx.STATUS.NotExecuted;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void ResetAllTests()
        {
            using (TestingEntities entities = TestEntitiesConnection.CreateEntities())
            {
                string strName = m_strName;

                List <Session> rgSessions = entities.Sessions.Where(p => p.Session1 == strName).ToList();

                if (rgSessions.Count == 0)
                {
                    return;
                }

                Session s      = rgSessions[0];
                string  strCmd = "DELETE FROM[Testing].[dbo].[Tests] WHERE SessionID = " + s.ID.ToString();
                entities.ExecuteStoreCommand(strCmd);
            }
        }
Ejemplo n.º 4
0
        public void SaveToDatabase()
        {
            using (TestingEntities entities = TestEntitiesConnection.CreateEntities())
            {
                int    nTotalTestRunCount     = TotalTestRunCount;
                int    nTotalTestFailureCount = TotalTestFailureCount;
                double dfFailureRate          = (nTotalTestRunCount == 0) ? 0 : ((double)nTotalTestFailureCount / (double)nTotalTestRunCount);
                string strName = m_strName;

                Session        s;
                List <Session> rgSessions = entities.Sessions.Where(p => p.Session1 == strName).ToList();

                if (rgSessions.Count > 0)
                {
                    s = rgSessions[0];
                }
                else
                {
                    s          = new Session();
                    s.Session1 = strName;
                }

                decimal dTotalTestTiming = 1000 * 60 * 60 * 1;
                if (TotalTestTiming.TotalMilliseconds < (double)dTotalTestTiming)
                {
                    dTotalTestTiming = (decimal)TotalTestTiming.TotalMilliseconds;
                }

                s.TimeStamp         = DateTime.Now;
                s.TotalTestsRun     = TotalTestRunCount;
                s.TotalTestFailures = TotalTestFailureCount;
                s.TestFailureRate   = (decimal)dfFailureRate;
                s.TotalTestTiming   = dTotalTestTiming;
                s.Path = m_strPath;

                if (rgSessions.Count == 0)
                {
                    entities.Sessions.AddObject(s);
                }

                entities.SaveChanges();

                foreach (TestClass tc in m_rgClasses)
                {
                    foreach (MethodInfoEx mi in tc.Methods)
                    {
                        Test        t;
                        List <Test> rgTest = entities.Tests.Where(p => p.SessionID == s.ID && p.TestGroup == tc.Name && p.TestMethod == mi.Name).ToList();

                        if (rgTest.Count > 0)
                        {
                            t = rgTest[0];
                        }
                        else
                        {
                            t            = new Test();
                            t.TestGroup  = tc.Name;
                            t.TestMethod = mi.Name;
                            t.SessionID  = s.ID;
                        }

                        dTotalTestTiming = 1000 * 60 * 60 * 1;
                        if (mi.TestTiming.TotalMilliseconds < (double)dTotalTestTiming)
                        {
                            dTotalTestTiming = (decimal)mi.TestTiming.TotalMilliseconds;
                        }

                        t.ErrorString   = getString(mi.ErrorInfo.FullErrorString, 1023);
                        t.ErrorLocation = getString(mi.ErrorInfo.FullErrorStringLocation, 1023);
                        t.Success       = (mi.Status == MethodInfoEx.STATUS.Passed) ? true : false;
                        t.TestTiming    = dTotalTestTiming;

                        if (rgTest.Count == 0)
                        {
                            entities.Tests.AddObject(t);
                        }
                    }
                }

                entities.SaveChanges();
            }
        }