public void OpenXmlElementConstructorOuterXmlTest() { // Check bug #484153. var outerXmlWithXmlDecl = "<?xml version=\"1.0\" encoding=\"utf-8\"?><customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\"></customUI>"; var ex1 = Assert.Throws <ArgumentException>(() => new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(outerXmlWithXmlDecl)); Assert.StartsWith(ExceptionMessages.InvalidOuterXml, ex1.Message); // Valid outer xml var validOuterXmlWithPrefix = "<mso:customUI xmlns:mso=\"http://schemas.microsoft.com/office/2006/01/customui\" />"; var validOuterXml = "<customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\"></customUI>"; var cUi2 = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(validOuterXml); Assert.Equal(validOuterXmlWithPrefix, cUi2.OuterXml); // Valid outer xml but starting with whitespace. var validOuterXmlWithWhitespaces = " <customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\"></customUI>"; var cUi3 = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(validOuterXmlWithWhitespaces); // The whitespace should be trimmed when getting OuterXml. Assert.Equal(validOuterXmlWithPrefix, cUi2.OuterXml); // verify bug #671248 var paragraphXml = "<w:p xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"w14\" " + "xmlns:w14=\"http://schemas.microsoft.com/office/word/2007/5/30/wordml\" " + "xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w14:paraId=\"017B6C57\" w14:editId=\"32F17AD3\" w:rsidR=\"00A35C47\" />"; var p = new Paragraph(paragraphXml); Assert.NotNull(p.MCAttributes); Assert.Equal(2, p.ExtendedAttributes.Count()); Assert.NotNull(p.RsidParagraphAddition); }
public void OpenXmlElementConstructorOuterXmlTest() { // Check bug #484153. string outerXmlWithXmlDecl = "<?xml version=\"1.0\" encoding=\"utf-8\"?><customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\"></customUI>"; try { DocumentFormat.OpenXml.Office.CustomUI.CustomUI cUi = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(outerXmlWithXmlDecl); Assert.True(false); // Assert.Fail("Expected InvalidOperationException is not thrown"); } catch (ArgumentException ex1) { Assert.True(ex1.Message.StartsWith(ExceptionMessages.InvalidOuterXml)); } // Valid outer xml string validOuterXml = "<customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\"></customUI>"; DocumentFormat.OpenXml.Office.CustomUI.CustomUI cUi2 = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(validOuterXml); Assert.Equal(validOuterXml, cUi2.OuterXml); // Valid outer xml but starting with whitespaces. string validOuterXmlWithWhitespaces = " <customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\"></customUI>"; DocumentFormat.OpenXml.Office.CustomUI.CustomUI cUi3 = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(validOuterXmlWithWhitespaces); // The whitespaces should be trimmed when getting OuterXml. Assert.Equal(validOuterXml, cUi2.OuterXml); // verify bug #671248 string paragraphXml = "<w:p xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"w14\" " + "xmlns:w14=\"http://schemas.microsoft.com/office/word/2007/5/30/wordml\" " + "xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w14:paraId=\"017B6C57\" w14:editId=\"32F17AD3\" w:rsidR=\"00A35C47\" />"; var p = new Paragraph(paragraphXml); Assert.NotNull(p.MCAttributes); Assert.Equal(2, p.ExtendedAttributes.Count()); Assert.NotNull(p.RsidParagraphAddition); }