Beispiel #1
0
 public FileContentResult DownloadXML()
 {
     if ((Boolean)Session["region"])
     {
         var list = (List <TopRegionWorld>)Session["infoExport"];
         var xml  = files.GenerateToXML <List <TopRegionWorld> >(list);
         return(File(new System.Text.UTF8Encoding().GetBytes(xml), "text/xml", "Top10WorldCovidCases.xml"));
     }
     else
     {
         var list = (List <CasesRegion>)Session["infoExport"];
         var xml  = files.GenerateToXML <List <CasesRegion> >(list);
         return(File(new System.Text.UTF8Encoding().GetBytes(xml), "text/xml", "Top10CovidCases[" + list.First().region.name + "].xml"));
     }
 }
        public void GenerateToXMLTest()
        {
            GenerateFiles files = GenerateFiles.getInstance();

            List <Region> testList = new List <Region>();

            testList.Add(new Region("P1", "prueba1"));
            testList.Add(new Region("P2", "prueba2"));
            StringWriter  sw = new StringWriter();
            XmlSerializer s  = new XmlSerializer(testList.GetType(), new XmlRootAttribute("Data"));

            s.Serialize(sw, testList);
            var stest = sw.ToString();

            var result = files.GenerateToXML <List <Region> >(testList);

            Assert.AreEqual(result, stest);
        }