Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="worksheet"></param>
        /// <param name="listObject"></param>
        /// <param name="listRow"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public TestStep CompileFromListRow(
            Excel.Workbook workbook,
            Excel.Worksheet worksheet,
            Excel.ListObject listObject,
            Excel.ListRow listRow,
            Dictionary <string, string> data)
        {
            if (null == listObject)
            {
                throw new ArgumentNullException("listObject");
            }

            if (null == listRow)
            {
                throw new ArgumentNullException("listRow");
            }

            ExcelHelper.SetColor(listRow.Range, Constants.ColorNone);
            ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Error, string.Empty);

            string name = ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Command);

            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            try
            {
                var command = TestCommandFactory.CreateCommand(name);
                var target  = this.GetValue(data, ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Target));
                var value   = this.GetValue(data, ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Value));

                this.SyntaxCheck(command, target, value);

                var step = new TestStep(
                    workbook,
                    worksheet,
                    listRow,
                    command,
                    target,
                    value);

                return(step);
            }
            catch (Exception ex)
            {
                Log.Logger.Warn(ex);
                ExcelHelper.SetColor(listRow.Range, Constants.ColorPink);
                Excel.Range range = ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Error, ex.Message);
                //ExcelHelper.AddComment(range, ex.Message);
                throw;
            }
        }
        public static Excel.ListRow GetEmptyRow(Excel.ListObject listObject)
        {
            Excel.ListRow theListRow = null;

            ForEach(listObject, (listRow) =>
            {
                var s = ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Command);
                if (string.IsNullOrWhiteSpace(s))
                {
                    theListRow = listRow;
                    return(false);
                }

                return(true);
            });

            if (null != theListRow)
            {
                return(theListRow);
            }

            return(ListObjectHelper.AddRow(listObject, true));
        }
Пример #3
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);
        }