Ejemplo n.º 1
0
        private T GetTestDataObject <T>(TestCaseWrapper <T> testCaseWrapper, TestSourceWrapper <DataTable, DataRow> testSource)
            where T : new()
        {
            var testCase = testCaseWrapper.Initialize.Invoke();

            for (int i = 0; i < testSource.Table.Columns.Count; i++)
            {
                var value = testSource.Row[i];
                var key   = testSource.Table.Columns[i].ColumnName;

                testCaseWrapper.SetupValue.Invoke(testCase, key, value);
            }

            return(testCase);
        }
Ejemplo n.º 2
0
        private IEnumerable <T> ReadDataFromSource <T>(TestCaseWrapper <T> testCaseWrapper)
            where T : new()
        {
            using (var excelPackage = new ExcelPackage(new FileInfo(FilePath)))
            {
                var worksheets = excelPackage.Workbook.Worksheets;
                var sheet      = worksheets.ToList().First(s => s.Name == SheetName);

                for (int rowIndex = FirstDataRow; rowIndex <= sheet.Dimension.End.Row; rowIndex++)
                {
                    yield return(GetTestDataObject(testCaseWrapper,
                                                   new TestSourceWrapper <ExcelWorksheet, int>(sheet, rowIndex)));
                }
            }
        }
Ejemplo n.º 3
0
        private IEnumerable <T> ReadDataFromSource <T>(TestCaseWrapper <T> testCaseWrapper)
            where T : new()
        {
            using (var sr = new StreamReader(FilePath))
            {
                string line;

                while ((line = sr.ReadLine()) != null)
                {
                    var @object = JsonConvert.DeserializeObject <T>(line);

                    yield return(GetTestDataObject(testCaseWrapper, line));
                }
            }
        }
Ejemplo n.º 4
0
        private T GetTestDataObject <T>(TestCaseWrapper <T> testCaseWrapper, TestSourceWrapper <ExcelWorksheet, int> testSource)
            where T : new()
        {
            var testCase       = testCaseWrapper.Initialize.Invoke();
            var endColumnIndex = testSource.Table.Dimension.End.Column;

            for (int columnIndex = LabelDataRow; columnIndex <= endColumnIndex; columnIndex++)
            {
                var labelCell = testSource.Table.Cells[LabelDataRow, columnIndex];
                var key       = labelCell.Value.ToString();
                var value     = testSource.Table.Cells[testSource.Row, columnIndex].Value;

                testCaseWrapper.SetupValue.Invoke(testCase, key, value);
            }

            return(testCase);
        }
Ejemplo n.º 5
0
        private T GetTestDataObject <T>(TestCaseWrapper <T> testCaseWrapper, string @case)
            where T : new()
        {
            var @object = JsonConvert.DeserializeObject <T>(@case);

            if (typeof(T) != typeof(TestCase <,>))
            {
                return(@object);
            }

            var testCase   = testCaseWrapper.Initialize.Invoke();
            var properties = @object.GetType().GetProperties();

            foreach (var property in properties)
            {
                var value = property.GetValue(@object);

                testCaseWrapper.SetupValue.Invoke(testCase, property.Name, value);
            }

            return(testCase);
        }
Ejemplo n.º 6
0
        private IEnumerable <T> ReadDataFromSource <T>(TestCaseWrapper <T> testCaseWrapper)
            where T : new()
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                var command = new SqlCommand($"SELECT * FROM {TableName}", connection);

                using (var sqlDataAdapter = new SqlDataAdapter(command))
                {
                    var dataTable = sqlDataAdapter.GetAsDataTable();

                    foreach (DataRow row in dataTable.Rows)
                    {
                        yield return(GetTestDataObject(testCaseWrapper,
                                                       new TestSourceWrapper <DataTable, DataRow>(dataTable, row)));
                    }
                }

                connection.Close();
            }
        }