Пример #1
0
        ///* bool GetDataPoolDataIndex(string value, out int index)
        // * return the value index.
        // * eg: data1.value1 will return 1, data1.value2 will return 2.
        // * we use this index to load actual data.
        // */
        //private bool GetDataPoolDataIndex(string value, out int index)
        //{
        //    index = -1;

        //    if (String.IsNullOrEmpty(value))
        //    {
        //        return false;
        //    }

        //    //match datapool
        //    if (_dataPoolReg.IsMatch(value))
        //    {
        //        string str1 = _dataPoolReg.Match(value).Value;
        //        try
        //        {
        //            str1 = str1.Replace(" ", "");
        //            str1 = str1.Replace("\t", "");

        //            //dot means the string contains datapool name.
        //            //we must specific the datapool name at the first time, eg: {data1.value1}
        //            //after the 1st, we just need the value, eg:{value2}
        //            int dotPos = str1.IndexOf('.');
        //            if (dotPos > 1)
        //            {
        //                //find value string, eg: value1
        //                string valueX = str1.Substring(dotPos, str1.Length - dotPos);

        //                //check if number is found.
        //                if (_numberReg.IsMatch(valueX))
        //                {
        //                    //if found, get the number.
        //                    if (int.TryParse(_numberReg.Match(valueX).Value, out index))
        //                    {
        //                        if (index > 0 && index < _parser.MaxDataCount)
        //                        {
        //                            return true;
        //                        }
        //                    }
        //                }

        //            }
        //            else
        //            {
        //                if (_numberReg.IsMatch(str1))
        //                {
        //                    if (int.TryParse(_numberReg.Match(str1).Value, out index))
        //                    {
        //                        if (index > 0 && index < _parser.MaxDataCount)
        //                        {
        //                            return true;
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        catch
        //        {
        //        }

        //    }

        //    return false;
        //}

        /* List<TestStep> InsertDataValueToSub(List<TestStep> originSteps, string dataPoolName)
         * return the actual test steps.
         * will replace the datapool string with actual data.
         */
        private List <TestStep> InsertDataValueToSub(List <TestStep> originSteps, string dataPoolName)
        {
            if (originSteps == null || String.IsNullOrEmpty(dataPoolName))
            {
                throw new CannotLoadSubException("Sub steps and/or Data pool name can not be null.");
            }

            TestDataPool dataPool;

            try
            {
                if (this._dataEngine == null)
                {
                    this._dataEngine = DataEngine.GetInstance();
                }

                dataPool = this._dataEngine.GetDataPoolByName(dataPoolName);
            }
            catch
            {
                throw new CannotLoadSubException("Can not load data pool by name:" + dataPoolName);
            }

            List <TestStep> stepsWithData = new List <TestStep>(originSteps.Count * 2);
            List <string[]> datas         = dataPool._data;

            foreach (string[] sArr in datas)
            {
                for (int i = 0; i < originSteps.Count; i++)
                {
                    TestStep newStep = InsertDataToSingleTestStep(originSteps[i], sArr);
                    stepsWithData.Add(newStep);
                }
            }

            return(stepsWithData);
        }
Пример #2
0
        ///* bool GetDataPoolDataIndex(string value, out int index)
        // * return the value index.
        // * eg: data1.value1 will return 1, data1.value2 will return 2.
        // * we use this index to load actual data.
        // */
        //private bool GetDataPoolDataIndex(string value, out int index)
        //{
        //    index = -1;
        //    if (String.IsNullOrEmpty(value))
        //    {
        //        return false;
        //    }
        //    //match datapool
        //    if (_dataPoolReg.IsMatch(value))
        //    {
        //        string str1 = _dataPoolReg.Match(value).Value;
        //        try
        //        {
        //            str1 = str1.Replace(" ", "");
        //            str1 = str1.Replace("\t", "");
        //            //dot means the string contains datapool name.
        //            //we must specific the datapool name at the first time, eg: {data1.value1}
        //            //after the 1st, we just need the value, eg:{value2}
        //            int dotPos = str1.IndexOf('.');
        //            if (dotPos > 1)
        //            {
        //                //find value string, eg: value1
        //                string valueX = str1.Substring(dotPos, str1.Length - dotPos);
        //                //check if number is found.
        //                if (_numberReg.IsMatch(valueX))
        //                {
        //                    //if found, get the number.
        //                    if (int.TryParse(_numberReg.Match(valueX).Value, out index))
        //                    {
        //                        if (index > 0 && index < _parser.MaxDataCount)
        //                        {
        //                            return true;
        //                        }
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                if (_numberReg.IsMatch(str1))
        //                {
        //                    if (int.TryParse(_numberReg.Match(str1).Value, out index))
        //                    {
        //                        if (index > 0 && index < _parser.MaxDataCount)
        //                        {
        //                            return true;
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        catch
        //        {
        //        }
        //    }
        //    return false;
        //}
        /* List<TestStep> InsertDataValueToSub(List<TestStep> originSteps, string dataPoolName)
         * return the actual test steps.
         * will replace the datapool string with actual data.
         */
        private List<TestStep> InsertDataValueToSub(List<TestStep> originSteps, string dataPoolName)
        {
            if (originSteps == null || String.IsNullOrEmpty(dataPoolName))
            {
                throw new CannotLoadSubException("Sub steps and/or Data pool name can not be null.");
            }

            TestDataPool dataPool;

            try
            {
                if (this._dataEngine == null)
                {
                    this._dataEngine = DataEngine.GetInstance();
                }

                dataPool = this._dataEngine.GetDataPoolByName(dataPoolName);
            }
            catch
            {
                throw new CannotLoadSubException("Can not load data pool by name:" + dataPoolName);
            }

            List<TestStep> stepsWithData = new List<TestStep>(originSteps.Count * 2);
            List<string[]> datas = dataPool._data;

            foreach (string[] sArr in datas)
            {
                for (int i = 0; i < originSteps.Count; i++)
                {
                    TestStep newStep = InsertDataToSingleTestStep(originSteps[i], sArr);
                    stepsWithData.Add(newStep);
                }
            }

            return stepsWithData;
        }