public void Export_Binary( ) { IEntityXmlImporter importer = Factory.EntityXmlImporter; IEntityXmlExporter exporter = Factory.EntityXmlExporter; EntityXmlImportResult result; long entityId; // Import - to set up test try { using (RunAsImportExportRole( )) using (Stream stream = EntityXmlImporterTests.GetStream("TestPhoto.xml")) using (StreamReader reader = new StreamReader(stream)) { string xml1 = reader.ReadToEnd( ); result = importer.ImportXml(xml1, EntityXmlImportSettings.Default); entityId = result.RootEntities.Single( ); } } catch (Exception ex) { throw new Exception("Import failed during setup for export test", ex); } // Export string xml; using (RunAsImportExportRole( )) { xml = exporter.GenerateXml(entityId, EntityXmlExportSettings.Default); } // Verify XmlDocument doc = new XmlDocument( ); doc.LoadXml(xml); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); // Note: can't get xpath to work with default namespace ns.AddNamespace("c", "core"); ns.AddNamespace("k", "console"); string expectedHash = "BN7ED5KVSPBOQQL2OELSONW25BI5MBPWS2JSRHQDIO2KW4UBGGMA"; XmlElement e = doc.SelectSingleNode($"/c:xml/c:binaries/c:binary[@hash='{expectedHash}']", ns) as XmlElement; Assert.That(e, Is.Not.Null, "Binary element missing"); string base64 = e.InnerText; Assert.That(base64, Is.StringStarting("H4sIAAAAAAAEAOsM8").And.StringEnding("lNAJmM74+OAQAA")); }
public void Export_Document( ) { IEntityXmlImporter importer = Factory.EntityXmlImporter; IEntityXmlExporter exporter = Factory.EntityXmlExporter; EntityXmlImportResult result; long entityId; // Import - to set up test try { using (RunAsImportExportRole( )) using (Stream stream = EntityXmlImporterTests.GetStream("TestDocument.xml")) using (StreamReader reader = new StreamReader(stream)) { string xml1 = reader.ReadToEnd( ); result = importer.ImportXml(xml1, EntityXmlImportSettings.Default); entityId = result.RootEntities.Single( ); } } catch (Exception ex) { throw new Exception("Import failed during setup for export test", ex); } // Export string xml; using (RunAsImportExportRole( )) { xml = exporter.GenerateXml(entityId, EntityXmlExportSettings.Default); } // Verify XmlDocument doc = new XmlDocument( ); doc.LoadXml(xml); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); // Note: can't get xpath to work with default namespace ns.AddNamespace("c", "core"); ns.AddNamespace("k", "console"); string expectedHash = "RV6PPKR5NJHP4GU76KIZ2HXB5BX3SPRKDQAIWQL33W7ADWUEOUJQ"; XmlElement e = doc.SelectSingleNode($"/c:xml/c:documents/c:document[@hash='{expectedHash}']", ns) as XmlElement; Assert.That(e, Is.Not.Null, "Document element missing"); string base64 = e.InnerText; Assert.That(base64, Is.StringStarting("H4sIAAAAAAAEAO16ZVRcS7P2QHBCcIK7uwQJGtw").And.StringEnding("r/wGi+uxzRi0AAA==")); }
public void Export_Nested_SimplifiedReport( ) { IEntityRepository repository = Factory.EntityRepository; IEntityXmlImporter importer = Factory.EntityXmlImporter; EntityXmlImportResult result; string xml; long entityId = 0; // Import using (RunAsImportExportRole()) using (Stream stream = EntityXmlImporterTests.GetStream("SimplifiedReport.xml")) using (StreamReader reader = new StreamReader(stream)) { xml = reader.ReadToEnd( ); result = importer.ImportXml(xml, EntityXmlImportSettings.Default); } try { entityId = result.RootEntities.Single( ); // Export IEntityXmlExporter exporter = Factory.EntityXmlExporter; string xml2; using (RunAsImportExportRole( )) { xml2 = exporter.GenerateXml(entityId, EntityXmlExportSettings.Default); } XmlDocument doc = new XmlDocument( ); doc.LoadXml(xml2); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); // Note: can't get xpath to work with default namespace ns.AddNamespace("c", "core"); ns.AddNamespace("k", "console"); XmlElement r = doc.SelectSingleNode("//c:report", ns) as XmlElement; Assert.That(r, Is.Not.Null); Assert.That(r.SelectSingleNode("@id", ns)?.Value, Is.EqualTo("7faec068-162c-4e99-995b-e84f9832fae0")); Assert.That(r.SelectSingleNode("@typeId", ns), Is.Null); Assert.That(r.SelectSingleNode("c:name", ns)?.InnerText, Is.EqualTo("Simple herb")); Assert.That(r.SelectSingleNode("c:rootNode", ns), Is.Not.Null); Assert.That(r.SelectSingleNode("c:rootNode/c:resourceReportNode[@id='5e7c086c-08e5-4aa7-99dc-b4e94d787548']", ns), Is.Not.Null); Assert.That(r.SelectSingleNode("c:rootNode/c:resourceReportNode[@id='5e7c086c-08e5-4aa7-99dc-b4e94d787548']/c:resourceReportNodeType", ns)?.InnerText, Is.EqualTo("a7bf22ab-6834-4d31-8133-5795acb27d69")); XmlElement col = r.SelectSingleNode("c:reportColumns/c:reportColumn[@id='1bb4d52c-0900-435e-9afd-dfb0a6c98b15']", ns) as XmlElement; Assert.That(col, Is.Not.Null); Assert.That(col.SelectSingleNode("c:name", ns)?.InnerText, Is.EqualTo("AA_Herb")); Assert.That(col.SelectSingleNode("c:columnIsHidden", ns)?.InnerText, Is.EqualTo("True")); Assert.That(col.SelectSingleNode("c:columnExpression", ns), Is.Not.Null); Assert.That(col.SelectSingleNode("c:columnExpression/c:fieldExpression[@id='1059aca5-d937-4876-9e54-661e95c14e0a']", ns), Is.Not.Null); Assert.That(col.SelectSingleNode("c:columnExpression/c:fieldExpression[@id='1059aca5-d937-4876-9e54-661e95c14e0a']/c:fieldExpressionField", ns)?.InnerText, Is.EqualTo("name")); Assert.That(col.SelectSingleNode("c:columnExpression/c:fieldExpression[@id='1059aca5-d937-4876-9e54-661e95c14e0a']/c:sourceNode", ns)?.InnerText, Is.EqualTo("5e7c086c-08e5-4aa7-99dc-b4e94d787548")); Assert.That(col.SelectSingleNode("c:columnGrouping/c:reportRowGroup[@id='22bf140b-78e6-4ca7-8169-3d817a8eb1d7']/c:groupingMethod", ns)?.InnerText, Is.EqualTo("groupList")); XmlElement a = doc.SelectSingleNode("//c:aliasMap", ns) as XmlElement; CheckAlias(a, ns, "c:columnExpression", "b4d64bef-e364-4786-ba7e-4a6b2c62d163", "rel"); } finally { Entity.Delete(entityId); } }