Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 0d34148

Browse files
author
Lowell Stewart
committed
Add a couple unit tests
for test cases borrowed from OXPT fork sergey-tihon/Clippit. The bugs driving these cases were fixed independently (using quite different approaches in each fork) but I still wanted to capture the test cases.
1 parent 662a0ce commit 0d34148

File tree

5 files changed

+739
-0
lines changed

5 files changed

+739
-0
lines changed

OpenXmlPowerTools.Tests/DocumentAssemblerTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,42 @@ public void DA102_Throws(string name, string data)
208208
});
209209
}
210210

211+
[Fact]
212+
public void DATemplateMaior()
213+
{
214+
// this test case was causing incorrect behavior of OpenXmlRegex when replacing fields in paragraphs that contained
215+
// lastRenderedPageBreak XML elements. Recent fixes relating to UnicodeMapper and OpenXmlRegex addressed it.
216+
string name = "DA-TemplateMaior.docx";
217+
DA101(name, "DA-templateMaior.xml", false);
218+
var assembledDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, name.Replace(".docx", "-processed-by-DocumentAssembler.docx")));
219+
var afterAssembling = new WmlDocument(assembledDocx.FullName);
220+
221+
var descendants = afterAssembling.MainDocumentPart.Value;
222+
223+
Assert.False(descendants.Contains(">"), "Found > on text");
224+
}
225+
226+
[Fact]
227+
public void DAXmlError()
228+
{
229+
/* The assembly below would originally (prior to bug fixes) cause an exception to be thrown during assembly: 
230+
System.ArgumentException : '', hexadecimal value 0x01, is an invalid character.
231+
*/
232+
string name = "DA-xmlerror.docx";
233+
string data = "DA-xmlerror.xml";
234+
235+
DirectoryInfo sourceDir = new DirectoryInfo("../../../../TestFiles/");
236+
var templateDocx = new FileInfo(Path.Combine(sourceDir.FullName, name));
237+
var dataFile = new FileInfo(Path.Combine(sourceDir.FullName, data));
238+
239+
var wmlTemplate = new WmlDocument(templateDocx.FullName);
240+
var xmlData = XElement.Load(dataFile.FullName);
241+
242+
var afterAssembling = DocumentAssembler.AssembleDocument(wmlTemplate, xmlData, out var returnedTemplateError);
243+
var assembledDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, templateDocx.Name.Replace(".docx", "-processed-by-DocumentAssembler.docx")));
244+
afterAssembling.SaveAs(assembledDocx.FullName);
245+
}
246+
211247
[Theory]
212248
[InlineData("DA025-TemplateDocument.docx", "DA-Data.xml", false)]
213249
public void DA103_UseXmlDocument(string name, string data, bool err)

TestFiles/DA-TemplateMaior.docx

24.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)