public void T044_PackageRelationshipSelectorFromPackage() { var docName = "plain.docx"; var ba = File.ReadAllBytes(docName); const string DocumentRelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; using (MemoryStream ms = new MemoryStream()) { ms.Write(ba, 0, ba.Length); using (Package package = Package.Open(ms, FileMode.Open)) { var mainPartUri = new Uri("/", UriKind.Relative); PackageRelationshipSelector prs = new PackageRelationshipSelector(mainPartUri, PackageRelationshipSelectorType.Type, DocumentRelationshipType); var cnt = prs.Select(package).Count(); Assert.Equal(cnt, 1); } } }
public void T046_PackageRelationshipSelectorFromPartUsingId() { var docName = "plain.docx"; var ba = File.ReadAllBytes(docName); const string DocumentRelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; using (MemoryStream ms = new MemoryStream()) { ms.Write(ba, 0, ba.Length); using (Package package = Package.Open(ms, FileMode.Open)) { PackageRelationship docPackageRelationship = package .GetRelationshipsByType(DocumentRelationshipType) .FirstOrDefault(); if (docPackageRelationship != null) { Uri documentUri = PackUriHelper .ResolvePartUri( new Uri("/", UriKind.Relative), docPackageRelationship.TargetUri); Assert.Throws<ArgumentNullException>(() => new PackageRelationshipSelector(null, PackageRelationshipSelectorType.Id, "rId1")); Assert.Throws<ArgumentNullException>(() => new PackageRelationshipSelector(documentUri, PackageRelationshipSelectorType.Id, null)); PackageRelationshipSelector prs = new PackageRelationshipSelector(documentUri, PackageRelationshipSelectorType.Id, "rId1"); var cnt = prs.Select(package).Count(); Assert.Equal(cnt, 1); } } } }
public void T045_PackageRelationshipSelectorFromPackageUsingId() { var docName = "plain.docx"; var ba = File.ReadAllBytes(docName); using (MemoryStream ms = new MemoryStream()) { ms.Write(ba, 0, ba.Length); using (Package package = Package.Open(ms, FileMode.Open)) { var mainPartUri = new Uri("/", UriKind.Relative); PackageRelationshipSelector prs = new PackageRelationshipSelector(mainPartUri, PackageRelationshipSelectorType.Id, "rId1"); var cnt = prs.Select(package).Count(); Assert.Equal(cnt, 1); } } }
public void T043_PackageRelationshipSelector() { var docName = "plain.docx"; var ba = TestFileLib.GetByteArray(docName); const string StylesRelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; using (MemoryStream ms = new MemoryStream()) { ms.Write(ba, 0, ba.Length); using (Package package = Package.Open(ms, FileMode.Open)) { var mainPartUri = new Uri("/word/document.xml", UriKind.Relative); PackageRelationshipSelector prs = new PackageRelationshipSelector(mainPartUri, PackageRelationshipSelectorType.Type, StylesRelationshipType); var cnt = prs.Select(package).Count(); Assert.Equal(cnt, 1); } } }