Example #1
0
        public void TestCellsReading()
        {
            var model = TestTableModel.Data.ToArray();

            foreach (var t in _tableTextReadersCollection)
            {
                var cells = t.Value.Select(r => //new TestTableModel.Row()
                {
                    var row  = new TestTableModel.Row();
                    row.Col0 = r.GetCellValue <string>(0);
                    //if (t.Key.ToLower().Contains("excel"))
                    //{
                    //    var val =  r.GetCellValue<double?>(1);
                    //    row.Col1 = (int)val;
                    //}
                    //else
                    row.Col1 = r.GetCellValue <int?>(1);
                    row.Col2 = r.GetCellValue <double?>(2);
                    row.Col3 = r.GetCellValue <DateTime?>(3);
                    row.Col4 = r.GetCellValue <TimeSpan?>(4);
                    return(row);
                }).ToArray();
                for (int i = 0; i < model.Length; i++)
                {
                    Assert.AreEqual(model[i][0] ?? "", cells[i].Col0 ?? "");
                    Assert.AreEqual(model[i][1], cells[i].Col1);
                    Assert.AreEqual(model[i][2], cells[i].Col2);
                    Assert.AreEqual(model[i][3], cells[i].Col3);
                    Assert.AreEqual(model[i][4], cells[i].Col4);
                }
            }
        }
Example #2
0
        public void TestSkippedRows()
        {
            //Заголовки должны быть правильными.
            //а первая строка должна быть с учетом Skip'a
            foreach (var t in _tableTextReadersCollection)
            {
                t.Value.StartRow          = 0;
                t.Value.SkippedRows       = 1;
                t.Value.IsFirstRowHeaders = true;
                Assert.AreEqual(t.Value.SourceHeaders[0], TestTableModel.Columns[0].Name);
                Assert.AreEqual(t.Value.SourceHeaders[1], TestTableModel.Columns[1].Name);

                var cells = t.Value.Select(r => //new TestTableModel.Row()
                {
                    var row  = new TestTableModel.Row();
                    row.Col0 = r.GetCellValue <string>(0);
                    row.Col1 = r.GetCellValue <int?>(1);
                    row.Col2 = r.GetCellValue <double?>(2);
                    row.Col3 = r.GetCellValue <DateTime?>(3);
                    row.Col4 = r.GetCellValue <TimeSpan?>(4);
                    return(row);
                }).ToArray();
                var model = TestTableModel.Data.ToArray();
                for (int i = 0; i < model.Length - t.Value.SkippedRows; i++)
                {
                    var v1 = model[i + t.Value.SkippedRows][0];
                    var v2 = cells[i].Col0;

                    var v3 = model[i + t.Value.SkippedRows][1];
                    var v4 = cells[i].Col1;

                    var v5 = model[i + t.Value.SkippedRows][2];
                    var v6 = cells[i].Col2;

                    Assert.AreEqual(model[i + t.Value.SkippedRows][0] ?? "", cells[i].Col0 ?? "");
                    Assert.AreEqual(model[i + t.Value.SkippedRows][1], cells[i].Col1);
                    Assert.AreEqual(model[i + t.Value.SkippedRows][2], cells[i].Col2);
                    Assert.AreEqual(model[i + t.Value.SkippedRows][3], cells[i].Col3);
                    Assert.AreEqual(model[i + t.Value.SkippedRows][4], cells[i].Col4);
                }
            }
        }