forked from nissl-lab/toxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExcelParserBaseTest.cs
172 lines (154 loc) · 8.81 KB
/
ExcelParserBaseTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Toxy.Test
{
public class ExcelParserBaseTest
{
public void BaseTestShowCalculatedResult(string filename)
{
}
public void BaseTestExtractSheetFooter(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.IsNull(ss.Tables[0].PageFooter);
parser.Context.Properties.Add("ExtractSheetFooter", "1");
ToxySpreadsheet ss2 = parser.Parse();
Assert.IsNotNull(ss2.Tables[0].PageFooter);
Assert.AreEqual("testdoc|test phrase|",ss2.Tables[0].PageFooter);
}
public void BaseTestWithoutHeader(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.IsNull(ss.Tables[0].PageHeader);
Assert.AreEqual(0, ss.Tables[0].HeaderRows.Count);
Assert.AreEqual(9, ss.Tables[0].Rows.Count);
}
public void BaseTestWithHeaderRow(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
parser.Context.Properties.Add("HasHeader", "1");
ToxySpreadsheet ss = parser.Parse();
Assert.AreEqual(1, ss.Tables[0].HeaderRows.Count);
Assert.AreEqual("A", ss.Tables[0].HeaderRows[0].Cells[0].Value);
Assert.AreEqual("B", ss.Tables[0].HeaderRows[0].Cells[1].Value);
Assert.AreEqual("C", ss.Tables[0].HeaderRows[0].Cells[2].Value);
Assert.AreEqual("D", ss.Tables[0].HeaderRows[0].Cells[3].Value);
Assert.AreEqual(3, ss.Tables[0].Rows.Count);
Assert.AreEqual("1", ss.Tables[0].Rows[0].Cells[0].Value);
Assert.AreEqual("2", ss.Tables[0].Rows[0].Cells[1].Value);
Assert.AreEqual("3", ss.Tables[0].Rows[0].Cells[2].Value);
Assert.AreEqual("4", ss.Tables[0].Rows[0].Cells[3].Value);
Assert.AreEqual("A1", ss.Tables[0].Rows[1].Cells[0].Value);
Assert.AreEqual("A2", ss.Tables[0].Rows[1].Cells[1].Value);
Assert.AreEqual("A3", ss.Tables[0].Rows[1].Cells[2].Value);
Assert.AreEqual("A4", ss.Tables[0].Rows[1].Cells[3].Value);
Assert.AreEqual("B1", ss.Tables[0].Rows[2].Cells[0].Value);
Assert.AreEqual("B2", ss.Tables[0].Rows[2].Cells[1].Value);
Assert.AreEqual("B3", ss.Tables[0].Rows[2].Cells[2].Value);
Assert.AreEqual("B4", ss.Tables[0].Rows[2].Cells[3].Value);
}
public void BaseTestExtractSheetHeader(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.IsNull(ss.Tables[0].PageHeader);
parser.Context.Properties.Add("ExtractSheetHeader", "1");
ToxySpreadsheet ss2 = parser.Parse();
Assert.IsNotNull(ss2.Tables[0].PageHeader);
Assert.AreEqual("|testdoc|test phrase", ss2.Tables[0].PageHeader);
}
public void BaseTestFillBlankCells(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.AreEqual(1, ss.Tables[0].Rows[0].Cells.Count);
Assert.AreEqual(0, ss.Tables[0].Rows[1].Cells.Count);
Assert.AreEqual(2, ss.Tables[0].Rows[2].Cells.Count);
Assert.AreEqual(2, ss.Tables[0].Rows[3].Cells.Count);
Assert.AreEqual(2, ss.Tables[0].Rows[4].Cells.Count);
parser.Context.Properties.Add("FillBlankCells", "1");
ToxySpreadsheet ss2 = parser.Parse();
Assert.AreEqual(3, ss2.Tables[0].Rows[0].Cells.Count);
Assert.AreEqual(3, ss2.Tables[0].Rows[1].Cells.Count);
Assert.AreEqual(3, ss2.Tables[0].Rows[2].Cells.Count);
Assert.AreEqual(3, ss2.Tables[0].Rows[3].Cells.Count);
Assert.AreEqual(3, ss2.Tables[0].Rows[4].Cells.Count);
}
public void BaseTestExcelContent(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.AreEqual(3, ss.Tables.Count);
Assert.AreEqual("Sheet1", ss.Tables[0].Name);
Assert.AreEqual("Sheet2", ss.Tables[1].Name);
Assert.AreEqual("Sheet3", ss.Tables[2].Name);
Assert.AreEqual(5, ss.Tables[0].Rows.Count);
Assert.AreEqual(0, ss.Tables[1].Rows.Count);
Assert.AreEqual(0, ss.Tables[2].Rows.Count);
ToxyTable table = ss.Tables[0];
Assert.AreEqual(1, table.Rows[0].RowIndex);
Assert.AreEqual(2, table.Rows[1].RowIndex);
Assert.AreEqual(3, table.Rows[2].RowIndex);
Assert.AreEqual(4, table.Rows[3].RowIndex);
Assert.AreEqual(5, table.Rows[4].RowIndex);
Assert.AreEqual(1, table.Rows[0].Cells.Count);
Assert.AreEqual(0, table.Rows[1].Cells.Count);
Assert.AreEqual(2, table.Rows[2].Cells.Count);
Assert.AreEqual(2, table.Rows[3].Cells.Count);
Assert.AreEqual(2, table.Rows[4].Cells.Count);
Assert.AreEqual("Employee Info", table.Rows[0].Cells[0].ToString());
Assert.AreEqual(1, table.Rows[0].Cells[0].CellIndex);
Assert.AreEqual("Last name:", table.Rows[2].Cells[0].ToString());
Assert.AreEqual(1, table.Rows[2].Cells[0].CellIndex);
Assert.AreEqual("lastName", table.Rows[2].Cells[1].ToString());
Assert.AreEqual(2, table.Rows[2].Cells[1].CellIndex);
Assert.AreEqual("First name:", table.Rows[3].Cells[0].ToString());
Assert.AreEqual("firstName", table.Rows[3].Cells[1].ToString());
Assert.AreEqual("SSN:", table.Rows[4].Cells[0].ToString());
Assert.AreEqual("ssn", table.Rows[4].Cells[1].ToString());
}
public void BaseTestExcelComment(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.AreEqual(3, ss.Tables.Count);
Assert.AreEqual(3, ss.Tables[0].Rows.Count);
Assert.AreEqual(0, ss.Tables[0].Rows[1].Cells[0].CellIndex);
Assert.AreEqual(2, ss.Tables[0].Rows[1].RowIndex);
//TODO: fix this comment without cell value
Assert.AreEqual("comment top row1 (index0)\n", ss.Tables[0].Rows[0].Cells[0].Comment);
Assert.AreEqual("comment top row3 (index2)\n", ss.Tables[0].Rows[1].Cells[0].Comment);
Assert.AreEqual("comment top row4 (index3)\n", ss.Tables[0].Rows[2].Cells[0].Comment);
}
public void BaseTestExcelFormatedString(string filename)
{
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));
ISpreadsheetParser parser = ParserFactory.CreateSpreadsheet(context);
ToxySpreadsheet ss = parser.Parse();
Assert.AreEqual(13, ss.Tables[0].Rows.Count);
Assert.AreEqual("Dates, all 24th November 2006", ss.Tables[0].Rows[0].Cells[0].ToString());
Assert.AreEqual("24/11/2006", ss.Tables[0].Rows[1].Cells[1].ToString());
Assert.AreEqual("2006/11/24", ss.Tables[0].Rows[2].Cells[1].ToString());
Assert.AreEqual("2006-11-24", ss.Tables[0].Rows[3].Cells[1].ToString());
Assert.AreEqual("06/11/24", ss.Tables[0].Rows[4].Cells[1].ToString());
Assert.AreEqual("24/11/06", ss.Tables[0].Rows[5].Cells[1].ToString());
Assert.AreEqual("24-11-06", ss.Tables[0].Rows[6].Cells[1].ToString());
Assert.AreEqual("10.52", ss.Tables[0].Rows[9].Cells[1].ToString());
Assert.AreEqual("10.520", ss.Tables[0].Rows[10].Cells[1].ToString());
Assert.AreEqual("10.5", ss.Tables[0].Rows[11].Cells[1].ToString());
Assert.AreEqual("£10.52", ss.Tables[0].Rows[12].Cells[1].ToString());
}
}
}