public void ChangeSingleMergefield_ShouldDoNothing_IfLengthIncorrect() { // Arrange var paragraph = GetMockParagraph(); paragraph.RemoveChild((Run)paragraph.ChildElements[0]); var expected = "original"; var fields = paragraph.Descendants <FieldCode>(); // Act _service.ChangeSingleMergefield(fields, "test"); var actual = paragraph.ChildElements[3].InnerText; // Assert Assert.AreEqual(expected, actual); }
public void ChangeSingleMergefield(string filePath, string mergefieldName = "DEBTOR__First_name_excl_middle", string correctValue = "Robert") { // Updates a merge field's value when we know the field name but not the current value using (WordprocessingDocument doc = WordprocessingDocument.Open(filePath, true)) { string completeMergeFieldName = $" MERGEFIELD {mergefieldName} "; var fields = doc.MainDocumentPart.RootElement.Descendants <FieldCode>().Where(x => x.Text.Contains(completeMergeFieldName)); _service.ChangeSingleMergefield(fields, correctValue); doc.MainDocumentPart.Document.Save(); } }