Exemple #1
0
        private TestDataSequence GetTestDataSequence(ITestCase testCase)
        {
            var dataSequence = new TestDataSequence();

            if (string.IsNullOrWhiteSpace(testCase.DataName))
            {
                var dummyData = new TestData();
                dataSequence.Enqueue(dummyData);
                return(dataSequence);
            }

            Excel.ListObject listObject = ListObjectHelper.GetByName(testCase.Workbook, testCase.DataName);

            if (null == listObject)
            {
                throw new InvalidOperationException("listObject is null.");
            }

            ListObjectHelper.ForEach(
                listObject,
                (listRow) =>
            {
                var data = new TestData();

                foreach (Excel.ListColumn listColumn in listObject.ListColumns)
                {
                    var value = ListRowHelper.Get(listRow, listColumn.Index);
                    data.Add(listColumn.Name, value);
                }

                dataSequence.Enqueue(data);
                return(true);
            });

            return(dataSequence);
        }
Exemple #2
0
        public TestSequence Compile(IEnumerable <TestCase> testCases)
        {
            if (null == testCases)
            {
                throw new ArgumentNullException("testCases");
            }
#if DEBUG
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif
            var testSequence = new TestSequence();
            int index        = 0;

            foreach (var testCase in testCases.Where(i => i.IsChecked))
            {
                Excel.ListObject listObject = testCase.ListObject;
                var dataSequence            = this.GetTestDataSequence(testCase);

                foreach (var data in dataSequence)
                {
                    var steps = new TestStepCollection(testCase);
                    testSequence.Enqueue(steps);

                    ListObjectHelper.ForEach(
                        listObject,
                        (listRow) =>
                    {
                        try
                        {
                            var step = this.CompileFromListRow(
                                testCase.Workbook,
                                testCase.Worksheet,
                                listObject,
                                listRow,
                                data);

                            if (null != step)
                            {
                                step.TestCase = testCase;
                                step.Index    = index++;
                                steps.Enqueue(step);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Logger.Warn(ex);
                            testSequence.CompileErrorCount++;
                            testCase.Result = TestResult.Failed;
                        }

                        return(true);
                    });
                }
            }

#if DEBUG
            sw.Stop();
            Log.Logger.Debug(testSequence.ToString());
            Log.Logger.DebugFormat("Elapsed = {0}", sw.Elapsed);
#endif

            return(testSequence);
        }