Example #1
0
        private void SendMessage(iTestBase.iTestBase.TestStateEnum tse, string testName, string category, string message, string dataValue = "", string constraint = "", bool logDb = true)
        {
            Dispatcher.Invoke((ThreadStart)delegate()
            {
                if (TestResultOc.Count > MAX_TESTRESULTOC_COUNT)
                    TestResultOc.RemoveAt(0);
                TestResultOc.Add(new TestResult()
                {
                    TestState = tse,
                    TestName = testName,
                    Category = category,
                    Message = message,
                    DataValue = dataValue,
                    Constraint = constraint
                });
                switch (tse)
                {
                    default:
                    case iTestBase.iTestBase.TestStateEnum.None:
                        break;
                    case iTestBase.iTestBase.TestStateEnum.Information:
                        InformationCountSingle++;
                        InformationCount++;
                        break;
                    case iTestBase.iTestBase.TestStateEnum.Pass:
                        PassCountSingle++;
                        PassCount++;
                        break;
                    case iTestBase.iTestBase.TestStateEnum.Fail:
                        FailCountSingle++;
                        FailCount++;
                        Dispatcher.Invoke((ThreadStart)delegate()
                        {
                            if (_curTgcUnderTest != null)
                            {
                                _curTgcUnderTest.FailImage = new BitmapImage();
                                _curTgcUnderTest.FailImage.BeginInit();
                                _curTgcUnderTest.FailImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/status_error.png");
                                _curTgcUnderTest.FailImage.EndInit();
                            }
                        }, null);
                        break;
                    case iTestBase.iTestBase.TestStateEnum.Error:
                        ErrorCountSingle++;
                        ErrorCount++;
                        Dispatcher.Invoke((ThreadStart)delegate()
                        {
                            if (_curTgcUnderTest != null)
                            {
                                _curTgcUnderTest.ErrorImage = new BitmapImage();
                                _curTgcUnderTest.ErrorImage.BeginInit();
                                _curTgcUnderTest.ErrorImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/status_ques.ico");
                                _curTgcUnderTest.ErrorImage.EndInit();
                            }
                        }, null);
                        break;
                }
                TotalCountSingle++;
                TotalCount++;

                //ListViewItem lvi = (ListViewItem)lvTestResults.ItemContainerGenerator.ContainerFromIndex(TestResultOc.Count - 1);
                //lvi.IsSelected = true;
                //lvTestResults.ScrollIntoView(lvi);
            }, null);

            if (DatabaseConnected == true && logDb == true)
            {
                DateTime dt = DateTime.Now;
                string strdt = dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day.ToString() + " " +
                    dt.Hour.ToString() + ":" + dt.Minute.ToString() + ":" + dt.Second.ToString();
                string sql = "INSERT INTO itester." + CommonOperations.GetValidDatabaseName(_curProject) + "testresult(msgidx,tcid,state,stime,msec,category,message,value,const) "
                    + "VALUES('" + _testResultIndex + "','" + _testColID + "','"
                    + ((int)tse).ToString() + "','" + strdt + "','" + dt.Millisecond + "','" + category + "','"
                    + message + "','" + dataValue + "','" + constraint + "')";
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = _mysqlConn;
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();

                //Thread.Sleep(100);
            }
        }
Example #2
0
        public void ConfigTestGroupCaseFromXML(iTestBase.iTestBase tb, XElement xeCofig)
        {
            Type t = tb.GetType();
            PropertyInfo[] pia = t.GetProperties();
            foreach (XElement xe in xeCofig.Elements("item"))
            {
                string sn = CommonOperations.ConvertXmlString2FileString(xe.Attribute("name").Value);
                string sv = CommonOperations.ConvertXmlString2FileString(xe.Attribute("value").Value);
                foreach (PropertyInfo pi in pia)
                {
                    string pt = pi.PropertyType.Name;
                    string ptb = pi.PropertyType.BaseType.Name;
                    if (string.Compare(ptb, "Enum") != 0
                        && !pi.PropertyType.IsValueType
                        && string.Compare(pt, "string") != 0)
                        break;

                    if (string.Compare(pi.Name, sn, true) == 0)
                    {
                        try
                        {
                            if (string.Compare(pt, "SByte") == 0)
                            {
                                pi.SetValue(tb, sbyte.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Byte") == 0)
                            {
                                pi.SetValue(tb, byte.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Char") == 0)
                            {
                                pi.SetValue(tb, char.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Int16") == 0)
                            {
                                pi.SetValue(tb, Int16.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "UInt16") == 0)
                            {
                                pi.SetValue(tb, UInt16.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Int32") == 0)
                            {
                                pi.SetValue(tb, Int32.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "UInt32") == 0)
                            {
                                pi.SetValue(tb, UInt32.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Int64") == 0)
                            {
                                pi.SetValue(tb, Int64.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "UInt64") == 0)
                            {
                                pi.SetValue(tb, UInt64.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Decimal") == 0)
                            {
                                pi.SetValue(tb, decimal.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "float") == 0)
                            {
                                pi.SetValue(tb, float.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "double") == 0)
                            {
                                pi.SetValue(tb, double.Parse(sv), null);
                            }
                            else if (string.Compare(pt, "Boolean") == 0)
                            {
                                pi.SetValue(tb, bool.Parse(sv), null);
                            }
                            else if (string.Compare(ptb, "Enum") == 0)
                            {
                                pi.SetValue(tb, Enum.Parse(pi.PropertyType, sv), null);
                            }
                            else if (string.Compare(pt, "String") == 0)
                            {
                                pi.SetValue(tb, sv, null);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogDispOc.Add(
                                new LogDisplayerItem()
                                {
                                    State = LogDisplayerItem.StateEnum.Error,
                                    Message = "Cannot parse \"" + sv + "\" for \" " + sn + "\"."
                                });
                            LogDispOc.Add(
                                new LogDisplayerItem()
                                {
                                    State = LogDisplayerItem.StateEnum.Error,
                                    Message = "Error message :"
                                });
                            LogDispOc.Add(
                                new LogDisplayerItem()
                                {
                                    State = LogDisplayerItem.StateEnum.Error,
                                    Message = ex.Message
                                });
                            ITCHasError = true;
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="testColInst"></param>
        /// <param name="groupCaseName"></param>
        /// <param name="level"></param>
        /// <param name="isCase"></param>
        /// <param name="testBaseInst"></param>
        /// <param name="testFilePath"></param>
        public TestGroupCase(TestCollection testColInst, TestGroupCase parent, string groupCaseName, bool isCase, iTestBase testBaseInst, string testFilePath)
        {
            if (testColInst == null)
                throw new ArgumentNullException("Cannot initialize TestGroupCase() because of the null parameter.");
            GlobalIndex = TestCollection.GetGlobalIndex();
            TestColInstance = testColInst;
            GroupCaseName = groupCaseName;
            int level = 0;
            TestGroupCase tgc = parent;
            while (tgc != null)
            {
                level++;
                tgc = tgc.TestGroupCaseParent;
            }
            DisplayLevel = level;
            IsCase = isCase;
            TestBaseInstance = testBaseInst;
            if (IsCase == true)
                TestBaseInstance.TestGroupCaseLocal = this;
            TestFilePath = testFilePath;

            GroupCaseImage = new BitmapImage();
            GroupCaseImage.BeginInit();
            if (IsCase == true)
                GroupCaseImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/group_case.png");
            else
            {
                if (TestGroupCaseOc.Count > 1)
                {
                    GroupCaseImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/group_expand.png");
                    _isExpanded = true;
                }
                else
                {
                    GroupCaseImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/group_collaps.png");
                    _isExpanded = false;
                }
            }
            GroupCaseImage.EndInit();

            //if (IsCase == true)
            //{
            //    PassImage = new BitmapImage();
            //    PassImage.BeginInit();
            //    PassImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/status_ok.png");
            //    PassImage.EndInit();

            //    FailImage = new BitmapImage();
            //    FailImage.BeginInit();
            //    FailImage.UriSource = new Uri("pack://application:,,,/Testempo;component/resources/status_error.png");
            //    FailImage.EndInit();
            //}

            if (parent != null)
            {
                TestGroupCaseParent = parent;
                int index = TestColInstance.FindLastSubGroupCaseDisplayIndex(parent);
                parent.TestGroupCaseOc.Add(this);
                TestGroupCaseParent.IsExpanded = true;
                TestColInstance.TestGroupCaseOcDisp.Insert(index + 1, this);
            }
            else
            {
                TestColInstance.TestGroupCaseOc.Add(this);
                TestColInstance.TestGroupCaseOcDisp.Add(this);
            }

            if (IsCase == true)
                TestBaseInstance.RunCountChangedEvent += new EventHandler<RunCountChangedEventArgs>(TestBaseInstance_RunCountChangedEvent_EventHandler);
        }