public void TestOnlyOneCorePropertiesPart_AddRelationship()
        {
            Stream     is1 = OpenXml4NetTestDataSamples.OpenComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
            OPCPackage pkg;

            pkg = OPCPackage.Open(is1);

            Uri partUri = CreateURI("/docProps/core2.xml");

            try
            {
                pkg.AddRelationship(PackagingUriHelper.CreatePartName(partUri), TargetMode.Internal,
                                    PackageRelationshipTypes.CORE_PROPERTIES);
                Assert.Fail("expected OPC compliance exception was not thrown");
            }
            catch (InvalidFormatException e)
            {
                throw;
            }
            catch (InvalidOperationException e)
            {
                // expected during successful test
                Assert.AreEqual("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.Message);
            }
            pkg.Revert();
        }
Пример #2
0
        private static string ExtractInvalidFormatMessage(string sampleNameSuffix)
        {
            Stream     is1 = OpenXml4NetTestDataSamples.OpenComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
            OPCPackage pkg;

            try {
                pkg = OPCPackage.Open(is1);
            }
            catch (InvalidFormatException e) {
                // no longer required for successful test
                return(e.Message);
            }

            pkg.Revert();
            throw new AssertionException("expected OPC compliance exception was not thrown");
        }
        private static String ExtractInvalidFormatMessage(String sampleNameSuffix)
        {
            Stream     is1 = OpenXml4NetTestDataSamples.OpenComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
            OPCPackage pkg;

            try
            {
                pkg = OPCPackage.Open(is1);
            }
            catch (InvalidFormatException e)
            {
                // expected during successful test
                return(e.Message);
            }

            pkg.Revert();
            // Normally must thrown an InvalidFormatException exception.
            throw new AssertFailedException("expected OPC compliance exception was not thrown");
        }