Beispiel #1
0
        /* TestDataPool GetDataPoolByName(string dataPoolName)
         * return expected datapool by name.
         */
        public TestDataPool GetDataPoolByName(string dataPoolName)
        {
            if (String.IsNullOrEmpty(dataPoolName))
            {
                throw new CannotLoadDataPoolException("Datapool name can not be empty.");
            }

            if (_parser == null)
            {
                throw new CannotLoadDataPoolException("Parser can not be null.");
            }

            if (this._allDataPool == null)
            {
                this._allDataPool = Parser.GetAllTestDataPool();
            }

            foreach (TestDataPool d in this._allDataPool)
            {
                //if same name, return
                if (String.Compare(d._datapoolName, dataPoolName, true) == 0)
                {
                    this._currentDataPool = d;
                    return(this._currentDataPool);
                }
            }

            throw new CannotLoadDataPoolException("Can not load data pool by name:" + dataPoolName);
        }
Beispiel #2
0
        /* TestDataPool GetDataPoolByName(string dataPoolName)
         * return expected datapool by name.
         */
        public TestDataPool GetDataPoolByName(string dataPoolName)
        {
            if (String.IsNullOrEmpty(dataPoolName))
            {
                throw new CannotLoadDataPoolException("Datapool name can not be empty.");
            }

            if (_parser == null)
            {
                throw new CannotLoadDataPoolException("Parser can not be null.");
            }

            if (this._allDataPool == null)
            {
                this._allDataPool = Parser.GetAllTestDataPool();
            }

            foreach (TestDataPool d in this._allDataPool)
            {
                //if same name, return
                if (String.Compare(d._datapoolName, dataPoolName, true) == 0)
                {
                    this._currentDataPool = d;
                    return this._currentDataPool;
                }
            }

            throw new CannotLoadDataPoolException("Can not load data pool by name:" + dataPoolName);
        }
Beispiel #3
0
        /* void GetDataPool(string DriverFile)
         * Parse the 3rd tab, datapool, store datapool to a list.
         */
        private void GetDataPool(string DriverFile)
        {
            if (String.IsNullOrEmpty(DriverFile) || !File.Exists(this._driveFile))
            {
                throw new DriveNotFoundException("Can not find driven file:" + DriverFile);
            }
            try
            {
                _excelReader.FileName = DriverFile;
                _excelReader.Sheet = "Data";
                _excelReader.Open();

                TestDataPool tmpPool = new TestDataPool();
                bool started = false;

                while (_excelReader.MoveNext())
                {

                    string dataPoolName = _excelReader.ReadByIndex(0);

                    //if the first column is not empty, means we meet a new datapool
                    if (!String.IsNullOrEmpty(dataPoolName) && !started)
                    {
                        started = true;
                        tmpPool._datapoolName = dataPoolName;
                        tmpPool._data = new List<string[]>(32);

                        continue;
                    }

                    //if the frist column is "END", means current datapool is end.
                    if (!String.IsNullOrEmpty(dataPoolName) && started && dataPoolName.ToUpper().IndexOf("END") == 0)
                    {
                        _myTestDataPoolList.Add(tmpPool);
                        started = false;
                    }

                    if (started)
                    {
                        //get the actual test data.
                        string[] currentDataLine = new string[MaxDataCount];
                        for (int i = 0; i < MaxDataCount && i < _excelReader.ColCount - 1; i++)
                        {
                            currentDataLine[i] = _excelReader.ReadByIndex(i + 1);
                        }
                        tmpPool._data.Add(currentDataLine);
                    }

                }

            }
            catch (Exception ex)
            {
                throw new BadFormatDriverFileException("Can not get test data pool: " + ex.ToString());
            }
            finally
            {
                _excelReader.Close();
            }
        }