예제 #1
0
        public void TestExportToXML()
        {

            XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("CustomXMLMappings.xlsx");

            foreach (POIXMLDocumentPart p in wb.GetRelations())
            {

                if (!(p is MapInfo))
                {
                    continue;
                }
                MapInfo mapInfo = (MapInfo)p;

                XSSFMap map = mapInfo.GetXSSFMapById(1);
                XSSFExportToXml exporter = new XSSFExportToXml(map);
                MemoryStream os = new MemoryStream();
                exporter.ExportToXML(os, true);
                os.Position = 0;
                XmlDocument xml = new XmlDocument();
                xml.Load(os);
                Assert.IsNotNull(xml);
                Assert.IsTrue(xml.OuterXml != "");


                String docente = xml.SelectSingleNode("//DOCENTE").InnerText.Trim();
                String nome = xml.SelectSingleNode("//NOME").InnerText.Trim();
                String tutor = xml.SelectSingleNode("//TUTOR").InnerText.Trim();
                String cdl = xml.SelectSingleNode("//CDL").InnerText.Trim();
                String durata = xml.SelectSingleNode("//DURATA").InnerText.Trim();
                String argomento = xml.SelectSingleNode("//ARGOMENTO").InnerText.Trim();
                String progetto = xml.SelectSingleNode("//PROGETTO").InnerText.Trim();
                String crediti = xml.SelectSingleNode("//CREDITI").InnerText.Trim();

                Assert.AreEqual("ro", docente);
                Assert.AreEqual("ro", nome);
                Assert.AreEqual("ds", tutor);
                Assert.AreEqual("gs", cdl);
                Assert.AreEqual("g", durata);
                Assert.AreEqual("gvvv", argomento);
                Assert.AreEqual("aaaa", progetto);
                Assert.AreEqual("aa", crediti);
            }
        }
예제 #2
0
        public void TestExportToXMLInverseOrder()
        {
            XSSFWorkbook wb = XSSFTestDataSamples
                              .OpenSampleWorkbook("CustomXmlMappings-inverse-order.xlsx");

            MapInfo mapInfo = null;

            foreach (POIXMLDocumentPart p in wb.GetRelations())
            {
                if (!(p is MapInfo))
                {
                    continue;
                }
                mapInfo = (MapInfo)p;

                XSSFMap         map      = mapInfo.GetXSSFMapById(1);
                XSSFExportToXml exporter = new XSSFExportToXml(map);
                MemoryStream    os       = new MemoryStream();
                exporter.ExportToXML(os, true);
                os.Position = 0;
                XmlDocument xml = new XmlDocument();
                xml.Load(os);
                Assert.IsNotNull(xml);
                Assert.IsTrue(xml.OuterXml != "");

                String docente   = xml.SelectSingleNode("//DOCENTE").InnerText.Trim();
                String nome      = xml.SelectSingleNode("//NOME").InnerText.Trim();
                String tutor     = xml.SelectSingleNode("//TUTOR").InnerText.Trim();
                String cdl       = xml.SelectSingleNode("//CDL").InnerText.Trim();
                String durata    = xml.SelectSingleNode("//DURATA").InnerText.Trim();
                String argomento = xml.SelectSingleNode("//ARGOMENTO").InnerText.Trim();
                String progetto  = xml.SelectSingleNode("//PROGETTO").InnerText.Trim();
                String crediti   = xml.SelectSingleNode("//CREDITI").InnerText.Trim();

                Assert.AreEqual("aa", nome);
                Assert.AreEqual("aaaa", docente);
                Assert.AreEqual("gvvv", tutor);
                Assert.AreEqual("g", cdl);
                Assert.AreEqual("gs", durata);
                Assert.AreEqual("ds", argomento);
                Assert.AreEqual("ro", progetto);
                Assert.AreEqual("ro", crediti);
            }
        }
예제 #3
0
        public void TestXPathOrdering()
        {
            XSSFWorkbook wb = XSSFTestDataSamples
                              .OpenSampleWorkbook("CustomXmlMappings-inverse-order.xlsx");

            MapInfo mapInfo = null;

            foreach (POIXMLDocumentPart p in wb.GetRelations())
            {
                if (p is MapInfo)
                {
                    mapInfo = (MapInfo)p;

                    XSSFMap         map      = mapInfo.GetXSSFMapById(1);
                    XSSFExportToXml exporter = new XSSFExportToXml(map);

                    Assert.AreEqual(1, exporter.Compare("/CORSO/DOCENTE", "/CORSO/NOME"));
                    Assert.AreEqual(-1, exporter.Compare("/CORSO/NOME", "/CORSO/DOCENTE"));
                }
            }
        }
예제 #4
0
        public void TestMultiTable()
        {
            XSSFWorkbook wb = XSSFTestDataSamples
                              .OpenSampleWorkbook("CustomXMLMappings-complex-type.xlsx");

            foreach (POIXMLDocumentPart p in wb.GetRelations())
            {
                if (p is MapInfo)
                {
                    MapInfo mapInfo = (MapInfo)p;

                    XSSFMap map = mapInfo.GetXSSFMapById(2);

                    Assert.IsNotNull(map);

                    XSSFExportToXml exporter = new XSSFExportToXml(map);
                    MemoryStream    os       = new MemoryStream();
                    exporter.ExportToXML(os, true);
                    String xml = Encoding.UTF8.GetString(os.ToArray());
                    Assert.IsNotNull(xml);

                    String[] regexConditions =
                    {
                        "<MapInfo",                                          "</MapInfo>",
                        "<Schema ID=\"1\" SchemaRef=\"\" Namespace=\"\" />",
                        "<Schema ID=\"4\" SchemaRef=\"\" Namespace=\"\" />",
                        "DataBinding",
                        "Map ID=\"1\"",
                        "Map ID=\"5\"",
                    };

                    foreach (String condition in regexConditions)
                    {
                        Regex pattern = new Regex(condition, RegexOptions.Compiled);
                        Assert.IsTrue(pattern.IsMatch(xml), condition);
                    }
                }
            }
        }
예제 #5
0
        public void TestMultiTable()
        {

            XSSFWorkbook wb = XSSFTestDataSamples
                    .OpenSampleWorkbook("CustomXMLMappings-complex-type.xlsx");

            foreach (POIXMLDocumentPart p in wb.GetRelations())
            {

                if (p is MapInfo)
                {
                    MapInfo mapInfo = (MapInfo)p;

                    XSSFMap map = mapInfo.GetXSSFMapById(2);

                    Assert.IsNotNull(map);

                    XSSFExportToXml exporter = new XSSFExportToXml(map);
                    MemoryStream os = new MemoryStream();
                    exporter.ExportToXML(os, true);
                    String xml = Encoding.UTF8.GetString(os.ToArray()); 
                    Assert.IsNotNull(xml);

                    String[] regexConditions = {
						"<MapInfo", "</MapInfo>",
						"<Schema ID=\"1\" SchemaRef=\"\" Namespace=\"\" />",
						"<Schema ID=\"4\" SchemaRef=\"\" Namespace=\"\" />",
						"DataBinding",
						"Map ID=\"1\"",
						"Map ID=\"5\"",
				};

                    foreach (String condition in regexConditions)
                    {
                        Regex pattern = new Regex(condition,RegexOptions.Compiled);
                        Assert.IsTrue(pattern.IsMatch(xml),condition);
                    }
                }
            }
        }
예제 #6
0
        public void TestXPathOrdering()
        {

            XSSFWorkbook wb = XSSFTestDataSamples
                    .OpenSampleWorkbook("CustomXmlMappings-inverse-order.xlsx");

            MapInfo mapInfo = null;

            foreach (POIXMLDocumentPart p in wb.GetRelations())
            {

                if (p is MapInfo)
                {
                    mapInfo = (MapInfo)p;

                    XSSFMap map = mapInfo.GetXSSFMapById(1);
                    XSSFExportToXml exporter = new XSSFExportToXml(map);

                    Assert.AreEqual(1, exporter.Compare("/CORSO/DOCENTE", "/CORSO/NOME"));
                    Assert.AreEqual(-1, exporter.Compare("/CORSO/NOME", "/CORSO/DOCENTE"));
                }
            }
        }