Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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"));
                }
            }
        }
Ejemplo n.º 3
0
        public void TestMapInfoExists()
        {
            XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("CustomXMLMappings.xlsx");

            MapInfo        mapInfo        = null;
            SingleXmlCells SingleXMLCells = null;

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


                    CT_MapInfo ctMapInfo = mapInfo.GetCTMapInfo();

                    Assert.IsNotNull(ctMapInfo);

                    Assert.AreEqual(1, ctMapInfo.Schema.Count);

                    foreach (XSSFMap map in mapInfo.GetAllXSSFMaps())
                    {
                        string xmlSchema = map.GetSchema();
                        Assert.IsNotNull(xmlSchema);
                    }
                }
            }

            XSSFSheet sheet1 = (XSSFSheet)wb.GetSheetAt(0);

            foreach (POIXMLDocumentPart p in sheet1.GetRelations())
            {
                if (p is SingleXmlCells)
                {
                    SingleXMLCells = (SingleXmlCells)p;
                }
            }
            Assert.IsNotNull(mapInfo);
            Assert.IsNotNull(SingleXMLCells);
        }
Ejemplo n.º 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);
                    }
                }
            }
        }