Example #1
0
        public void ExportTemplatesTest()
        {
            MockObjectRepository tdb        = TestDataGenerator.GenerateMockDataset1();
            List <Template>      templates  = tdb.Templates.ToList();
            IGSettingsManager    igSettings = new IGSettingsManager(tdb);

            TemplateExporter exporter = new TemplateExporter(tdb, templates, igSettings);
            string           actual   = exporter.GenerateXMLExport();

            Assert.IsNotNull(actual, "Export should have produced content.");
            Assert.AreNotEqual(string.Empty, actual, "Export should have produced content.");

            XmlDocument exportDoc = new XmlDocument();

            exportDoc.LoadXml(actual);

            XmlNamespaceManager nsManager = new XmlNamespaceManager(exportDoc.NameTable);

            nsManager.AddNamespace("lcg", "http://www.lantanagroup.com");

            XmlNodeList templateNodes = exportDoc.DocumentElement.SelectNodes("lcg:Template", nsManager);

            Assert.IsNotNull(templateNodes, "Did not find any templates in export.");
            Assert.AreEqual(4, templateNodes.Count, "Export should have produced three (4) Template elements.");

            XmlAttribute identifierAttribute = templateNodes[0].Attributes["identifier"];
            XmlAttribute implementationGuideTypeAttribute = templateNodes[0].Attributes["implementationGuideType"];
            XmlAttribute templateTypeAttribute            = templateNodes[0].Attributes["templateType"];
            XmlAttribute titleAttribute    = templateNodes[0].Attributes["title"];
            XmlAttribute bookmarkAttribute = templateNodes[0].Attributes["bookmark"];

            Assert.IsNotNull(identifierAttribute, "Couldn't find identifier attribute on Template.");
            Assert.AreEqual("1.2.3.4.5", identifierAttribute.Value, "Template's identifier has an incorrect value.");

            Assert.IsNotNull(implementationGuideTypeAttribute, "Couldn't find implementationGuideType attribute on Template.");
            Assert.AreEqual(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, implementationGuideTypeAttribute.Value, "Template's implementationGuideType has an incorrect value.");

            Assert.IsNotNull(templateTypeAttribute, "Couldn't find templateType attribute on Template.");
            Assert.AreEqual("Document", templateTypeAttribute.Value, "Template's templateType has an incorrect value.");

            Assert.IsNotNull(titleAttribute, "Couldn't find title attribute on Template.");
            Assert.AreEqual("Test Template 1", titleAttribute.Value, "Template's title has an incorrect value.");

            Assert.IsNotNull(bookmarkAttribute, "Couldn't find bookmark attribute on Template.");
            Assert.AreEqual("D_Test_Template_1", bookmarkAttribute.Value, "Template's bookmark has an incorrect value.");

            XmlNodeList constraintNodes = templateNodes[0].SelectNodes("lcg:Constraint", nsManager);

            Assert.IsNotNull(constraintNodes, "Did not find any constraints in the first template.");
            Assert.AreEqual(3, constraintNodes.Count, "Did not find the correct number of root-level constraints in the first exported template.");

            XmlNodeList childConstraintNodes = constraintNodes[1].SelectNodes("lcg:Constraint", nsManager);

            Assert.IsNotNull(childConstraintNodes, "Did not find any grand-child constraints in the first template.");
            Assert.AreEqual(1, childConstraintNodes.Count, "Did not find the correct number of grand-child constraints in the first exported template.");
        }
Example #2
0
        private string GenerateExport()
        {
            string             templateExport    = TemplateExporter.GenerateXMLExport(this.tdb, this.templates, this.igSettings, true, this.categories);
            LantanaXmlResolver resolver          = new LantanaXmlResolver();
            string             stylesheetContent = string.Empty;

            using (StreamReader stylesheetReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(StylesheetResource)))
            {
                stylesheetContent = stylesheetReader.ReadToEnd();
            }

            var export = TransformFactory.Transform(templateExport, stylesheetContent, StylesheetUri, resolver);

            if (includeVocabulary)
            {
                // Export the vocabulary for the implementation guide in SVS format
                VocabularyService vocService = new VocabularyService(tdb, false);
                string            vocXml     = vocService.GetImplementationGuideVocabulary(igSettings.ImplementationGuideId, 1000, 4, "utf-8");

                // Merge the two ATOM exports together
                XmlDocument exportDoc = new XmlDocument();
                exportDoc.LoadXml(export);

                // Remove extra xmlns attributes from vocabulary xml
                System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Parse(vocXml);
                foreach (var descendant in doc.Root.Descendants())
                {
                    var namespaceDeclarations = descendant.Attributes().Where(y => y.IsNamespaceDeclaration && y.Name.LocalName == "atom");
                    foreach (var namespaceDeclaration in namespaceDeclarations)
                    {
                        namespaceDeclaration.Remove();
                    }
                }
                vocXml = doc.ToString();

                XmlDocument vocDoc = new XmlDocument();
                vocDoc.LoadXml(vocXml);

                XmlNamespaceManager vocNsManager = new XmlNamespaceManager(vocDoc.NameTable);
                vocNsManager.AddNamespace("atom", "http://www.w3.org/2005/Atom");

                XmlNodeList vocEntryNodes = vocDoc.SelectNodes("/atom:feed/atom:entry", vocNsManager);

                foreach (XmlNode vocEntryNode in vocEntryNodes)
                {
                    XmlNode clonedVocEntryNode = exportDoc.ImportNode(vocEntryNode, true);
                    exportDoc.DocumentElement.AppendChild(clonedVocEntryNode);
                }

                // Format the XmlDocument and save it as a string
                using (StringWriter sw = new StringWriter())
                {
                    XmlTextWriter xtw = new XmlTextWriter(sw);
                    xtw.Formatting = Formatting.Indented;

                    exportDoc.WriteContentTo(xtw);
                    export = sw.ToString();
                }
            }

            return(export);
        }