public void SetAndUpdateCustomPropertyToDocument() { using (var withoutAttributes = new DocxDocument(Resources.DocumentWithoutAttributes)) using (var withAttribute = new DocxDocument(Resources.DocumentWithAttribute)) { withoutAttributes.SetCustomProperty("customAttributes", "Working1"); withoutAttributes.SetCustomProperty("customAttributes", "Working"); var withoutAttributesOuterXml = withoutAttributes.GetWordDocument().CustomFilePropertiesPart.Properties.Single(x => x.LocalName == "property").OuterXml; var withAttributeOuterXml = withAttribute.GetWordDocument().CustomFilePropertiesPart.Properties.Single(x => x.LocalName == "property").OuterXml; Assert.AreEqual(withAttributeOuterXml, withoutAttributesOuterXml); } }
public void SetCustomPropertyToDocumentIfItAlreadyHasProperties() { using (var withTwoAttributes = new DocxDocument(Resources.DocumentWithTwoAttributes)) using (var withAttribute = new DocxDocument(Resources.DocumentWithAttribute)) { withAttribute.SetCustomProperty("customAttributes2", "Working2"); var propertiesWithTwoAttributes = withTwoAttributes.GetWordDocument().CustomFilePropertiesPart.Properties; var propertiesWithAttribute = withAttribute.GetWordDocument().CustomFilePropertiesPart.Properties; Assert.AreEqual(propertiesWithTwoAttributes.First(x => x.LocalName == "property").OuterXml, propertiesWithAttribute.First(x => x.LocalName == "property").OuterXml); Assert.AreEqual(propertiesWithTwoAttributes.Last(x => x.LocalName == "property").OuterXml, propertiesWithAttribute.Last(x => x.LocalName == "property").OuterXml); } }