Пример #1
0
        public List <TestCase> GetTestCases()
        {
            //Excel.Application xlApp = new Excel.Application();
            //Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(_fileLocation);
            //Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            //Excel.Range xlRange = xlWorksheet.UsedRange;

            Console.WriteLine("Test Cases are currently being read.");

            int rowCount = _xlRange.Rows.Count;
            int colCount = _xlRange.Columns.Count;

            int headerRow = 7;

            List <int[]> rowNumbers = new List <int[]>();

            // Find subset of rows for each test case as a array of [Start, End] values
            int start = headerRow;

            for (int i = headerRow + 1; i <= rowCount; i++)
            {
                if (_xlRange.Cells[i, 4] != null && _xlRange.Cells[i, 4].Value2 != null)
                {
                    int[] currTestCase = { start, i - 1 };
                    rowNumbers.Add(currTestCase);
                    start = i;
                }
            }
            int[] lastTestCase = { start, rowCount };
            rowNumbers.Add(lastTestCase);

            //foreach (var currRows in rowNumbers)
            //{
            //    Console.WriteLine(currRows[0] + " " + currRows[1]);
            //}

            List <TestCase> res = new List <TestCase>();

            // First row is a list header row. Do not need for implementation.
            // This is assuming that the test case upload style is standardized

            // Iterate through each subset of rows for each test case
            using (var progress = new ProgressBar())
            {
                double totalCount = rowNumbers.Count;
                double currCount  = 1;

                foreach (var currRow in rowNumbers)
                {
                    currCount += 1;
                    progress.Report(currCount / totalCount);

                    int startRow = currRow[0];
                    int endRow   = currRow[1];

                    //int testVal = (int)char.GetNumericValue(xlRange.Cells[startRow, 6].Value2[0]);
                    //System.Diagnostics.Debug.WriteLine(testVal);

                    TestCase currTestCase = new TestCase();

                    if (_xlRange.Cells[startRow, 1].Value2 != null)
                    {
                        currTestCase.TestCaseId = Convert.ToInt32(_xlRange.Cells[startRow, 1].Value2);
                    }

                    if (_xlRange.Cells[startRow, 2].Value2 != null)
                    {
                        currTestCase.TestScenarios = new List <TestScenario>();

                        string   testScenarioIds     = _xlRange.Cells[startRow, 2].Value2.ToString();
                        string[] testScenarioIdArray = testScenarioIds.Split(',').Select(x => x.Trim())
                                                       .Where(x => !string.IsNullOrWhiteSpace(x))
                                                       .ToArray();
                        foreach (string testScenarioId in testScenarioIdArray)
                        {
                            TestScenario currTestScenario = new TestScenario
                            {
                                TestScenarioId = Convert.ToInt32(testScenarioId)
                            };
                            currTestCase.TestScenarios.Add(currTestScenario);
                        }
                    }

                    currTestCase.TestCaseName       = _xlRange.Cells[startRow, 4].Value2;
                    currTestCase.TestObjective      = _xlRange.Cells[startRow, 5].Value2;
                    currTestCase.TestDescription    = _xlRange.Cells[startRow, 6].Value2;
                    currTestCase.PreCondition       = _xlRange.Cells[startRow, 7].Value2;
                    currTestCase.Priority           = (int)char.GetNumericValue(_xlRange.Cells[startRow, 8].Value2[0]);
                    currTestCase.PriorityString     = _xlRange.Cells[startRow, 8].Value2;
                    currTestCase.Complexity         = _xlRange.Cells[startRow, 9].Value2;
                    currTestCase.ScenarioType       = _xlRange.Cells[startRow, 10].Value2;
                    currTestCase.Application        = _xlRange.Cells[startRow, 11].Value2;
                    currTestCase.ApplicationArea    = _xlRange.Cells[startRow, 12].Value2;
                    currTestCase.ApplicationProcess = _xlRange.Cells[startRow, 13].Value2;
                    currTestCase.ApplicationSubArea = _xlRange.Cells[startRow, 14].Value2;
                    currTestCase.TestCaseType       = _xlRange.Cells[startRow, 15].Value2;

                    currTestCase.UserName = _userName;

                    for (int i = startRow; i <= endRow; i++)
                    {
                        if (_xlRange.Cells[i, 16].Value2 != null && _xlRange.Cells[i, 17].Value2 != null && _xlRange.Cells[i, 18] != null)
                        {
                            currTestCase.AddStep(i - startRow + 1, _xlRange.Cells[i, 17].Value2, _xlRange.Cells[i, 18].Value2);
                        }
                        //currTestCase.AddStep(_xlRange.Cells[i, 16].Value2, _xlRange.Cells[i, 17].Value2);
                        //if (startRow == 325)
                        //{
                        //    Console.WriteLine(xlRange.Cells[i, 16].Value2 + " " + xlRange.Cells[i, 17].Value2);
                        //}
                    }

                    res.Add(currTestCase);
                }
            }

            Console.WriteLine(res.Count + " Test Cases have been read");

            return(res);
        }