public void WriteTaskHeaders(MSExcel2003XmlFile xmlFile, int tableIndex, bool isActive)
        {
            List <string> headers = GetHeaders(isActive);

            xmlFile.SetColumnWidths(tableIndex, headers.Select(h => GetHeaderWidth(h)).ToList());
            xmlFile.AddHeaderRow(tableIndex, headers);
        }
        public void MSExcel2003XmlFile_AddHeaderRow_GetHeaders()
        {
            //arrange
            string             comparisonFilename = "data/MSExcel2003XmlFile_AddHeaderRow_GetHeaders.txt";
            MSExcel2003XmlFile xmlFile            = new MSExcel2003XmlFile();
            string             title   = "title";
            List <string>      headers = new List <string>()
            {
                "Title", "Address", "Last Name"
            };
            //act
            int tableIndex = xmlFile.AddWorksheet(title);

            xmlFile.AddHeaderRow(tableIndex, headers);
            List <string> savedHeaders       = xmlFile.GetHeaders(tableIndex);
            List <int>    savedHeaderIndexes = headers.Select(h => xmlFile.GetHeaderIndex(tableIndex, h)).ToList();
            string        text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument);

            //assert
            Assert.AreEqual(headers.Count, savedHeaders.Count);
            Assert.AreEqual(headers.Count, savedHeaderIndexes.Count);
            for (int i = 0; i < headers.Count; i++)
            {
                Assert.AreEqual(headers[i], savedHeaders[i]);
                Assert.AreEqual(i, savedHeaderIndexes[i]);
            }
            Assert.AreEqual(Utilities.LoadText(comparisonFilename), text);
        }
Example #3
0
        public void WriteTo(MSExcel2003XmlFile xmlFile)
        {
            int tableIndex = xmlFile.AddWorksheet(SHEET_NAME);

            xmlFile.AddHeaderRow(tableIndex, new List <string>()
            {
                STATUS_NAME, ACTIVE_NAME, "", CATEGORY_NAME, "", ID_NAME
            });

            List <XmlNode> statusNodes   = Statuses.Select(status => xmlFile.GenerateTextCell(status.Name)).ToList();
            List <XmlNode> activeNodes   = Statuses.Select(status => xmlFile.GenerateTextCell((status.Active ? "Active" : "Inactive"))).ToList();          //todo: make constants, but not connected to table names
            List <XmlNode> categoryNodes = Categories.Select(category => xmlFile.GenerateTextCell(category)).ToList();

            xmlFile.AddColumns(tableIndex, new List <List <XmlNode> >()
            {
                statusNodes,
                activeNodes,
                new List <XmlNode>(),
                categoryNodes,
                new List <XmlNode>(),
                new List <XmlNode>()
                {
                    xmlFile.GenerateNumberCell(MaxId)
                }
            });
        }
        public void MSExcel2003XmlFile_AddColumns_GetColumnValues()
        {
            //arrange
            MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile();
            string             title   = "title";
            List <string>      headers = new List <string>()
            {
                "A", "B", "C"
            };
            List <object> valuesA = new List <object>()
            {
                "abc", 123, new DateTime(1999, 3, 2), 100
            };
            List <object> valuesB = new List <object>()
            {
                new DateTime(1777, 5, 4), "def", "ghijk", "lm", "nop", "qrstuv"
            };
            List <object> valuesC = new List <object>()
            {
                456, 400
            };
            List <List <object> > columns = new List <List <object> >()
            {
                valuesA, valuesB, valuesC
            };
            int maxRowCount = Math.Max(valuesA.Count, Math.Max(valuesB.Count, valuesC.Count));
            //act
            int tableIndex = xmlFile.AddWorksheet(title);

            xmlFile.AddHeaderRow(tableIndex, headers);
            xmlFile.AddColumns(tableIndex, columns);
            string        text                   = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument);
            List <string> savedValues0           = xmlFile.GetColumnValues(tableIndex, 0, firstRowIsHeader: true);
            List <string> savedValues1           = xmlFile.GetColumnValues(tableIndex, 1, firstRowIsHeader: true);
            List <string> savedValues2           = xmlFile.GetColumnValues(tableIndex, 2, firstRowIsHeader: true);
            List <string> savedValues0WithHeader = xmlFile.GetColumnValues(tableIndex, 0, firstRowIsHeader: false);
            List <string> savedValues1WithHeader = xmlFile.GetColumnValues(tableIndex, 1, firstRowIsHeader: false);
            List <string> savedValues2WithHeader = xmlFile.GetColumnValues(tableIndex, 2, firstRowIsHeader: false);
            List <string> savedValuesA           = xmlFile.GetColumnValues(tableIndex, "A");
            List <string> savedValuesB           = xmlFile.GetColumnValues(tableIndex, "B");
            List <string> savedValuesC           = xmlFile.GetColumnValues(tableIndex, "C");
            int           savedColumnCount       = xmlFile.GetColumnCount(tableIndex);

            //assert
            Assert.AreEqual(maxRowCount, savedValues0.Count);
            Assert.AreEqual(maxRowCount, savedValues1.Count);
            Assert.AreEqual(maxRowCount, savedValues2.Count);
            Assert.AreEqual(maxRowCount + 1, savedValues0WithHeader.Count);
            Assert.AreEqual(maxRowCount + 1, savedValues1WithHeader.Count);
            Assert.AreEqual(maxRowCount + 1, savedValues2WithHeader.Count);
            Assert.AreEqual(headers[0], savedValues0WithHeader[0]);
            Assert.AreEqual(headers[1], savedValues1WithHeader[0]);
            Assert.AreEqual(headers[2], savedValues2WithHeader[0]);
            for (int i = 0; i < valuesA.Count; i++)
            {
                if (valuesA[i] is DateTime)
                {
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValues0[i]);
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValues0WithHeader[i + 1]);
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValuesA[i]);
                }
                else
                {
                    Assert.AreEqual(valuesA[i].ToString(), savedValues0[i]);
                    Assert.AreEqual(valuesA[i].ToString(), savedValues0WithHeader[i + 1]);
                    Assert.AreEqual(valuesA[i].ToString(), savedValuesA[i]);
                }
            }
            for (int i = 0; i < valuesB.Count; i++)
            {
                if (valuesB[i] is DateTime)
                {
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValues1[i]);
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValues1WithHeader[i + 1]);
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValuesB[i]);
                }
                else
                {
                    Assert.AreEqual(valuesB[i].ToString(), savedValues1[i]);
                    Assert.AreEqual(valuesB[i].ToString(), savedValues1WithHeader[i + 1]);
                    Assert.AreEqual(valuesB[i].ToString(), savedValuesB[i]);
                }
            }
            for (int i = 0; i < valuesC.Count; i++)
            {
                if (valuesC[i] is DateTime)
                {
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesC[i]), savedValues2[i]);
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesC[i]), savedValues2WithHeader[i + 1]);
                    Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesC[i]), savedValuesC[i]);
                }
                else
                {
                    Assert.AreEqual(valuesC[i].ToString(), savedValues2[i]);
                    Assert.AreEqual(valuesC[i].ToString(), savedValues2WithHeader[i + 1]);
                    Assert.AreEqual(valuesC[i].ToString(), savedValuesC[i]);
                }
            }
            Assert.AreEqual(3, savedColumnCount);
        }