// ExStart:ShowChangesForHeaderAndFooterOrders private static void ShowChangesForHeaderAndFooterOrders(string dataDir) { Document doc = new Document(dataDir + "HeaderFooter.HeaderFooterOrder.docx"); // Assert that we use special header and footer for the first page // The order for this: first header\footer, even header\footer, primary header\footer Section firstPageSection = doc.FirstSection; ReplaceLog logger = new ReplaceLog(); FindReplaceOptions options = new FindReplaceOptions { ReplacingCallback = logger }; doc.Range.Replace(new Regex("(header|footer)"), "", options); doc.Save(dataDir + "HeaderFooter.HeaderFooterOrder.docx"); // Prepare our string builder for assert results without "DifferentFirstPageHeaderFooter" logger.ClearText(); // Remove special first page // The order for this: primary header, default header, primary footer, default footer, even header\footer firstPageSection.PageSetup.DifferentFirstPageHeaderFooter = false; doc.Range.Replace(new Regex("(header|footer)"), "", options); }
public void HeaderFooterOrder() { //ExStart //ExFor:IReplacingCallback //ExFor:Range.Replace(String, String, FindReplaceOptions) //ExSummary: Show changes for headers and footers order Document doc = new Document(MyDir + "HeaderFooter.HeaderFooterOrder.docx"); //Assert that we use special header and footer for the first page //The order for this: first header\footer, even header\footer, primary header\footer Section firstPageSection = doc.FirstSection; Assert.AreEqual(true, firstPageSection.PageSetup.DifferentFirstPageHeaderFooter); FindReplaceOptions options = new FindReplaceOptions(); ReplaceLog logger = new ReplaceLog(); options.ReplacingCallback = logger; doc.Range.Replace(new Regex("(header|footer)"), "", options); Assert.AreEqual("First header\r\nFirst footer\r\nSecond header\r\nSecond footer\r\nThird header\r\n" + "Third footer\r\n", logger.Text); //Prepare our string builder for assert results without "DifferentFirstPageHeaderFooter" logger.ClearText(); //Remove special first page //The order for this: primary header, default header, primary footer, default footer, even header\footer firstPageSection.PageSetup.DifferentFirstPageHeaderFooter = false; doc.Range.Replace(new Regex("(header|footer)"), "", options); Assert.AreEqual("Third header\r\nFirst header\r\nThird footer\r\nFirst footer\r\nSecond header\r\nSecond footer\r\n", logger.Text); }
[Test] //ExSkip public void HeaderFooterOrder() { Document doc = new Document(MyDir + "HeaderFooter.HeaderFooterOrder.docx"); // Assert that we use special header and footer for the first page // The order for this: first header\footer, even header\footer, primary header\footer Section firstPageSection = doc.FirstSection; Assert.AreEqual(true, firstPageSection.PageSetup.DifferentFirstPageHeaderFooter); ReplaceLog logger = new ReplaceLog(); FindReplaceOptions options = new FindReplaceOptions { ReplacingCallback = logger }; doc.Range.Replace(new Regex("(header|footer)"), "", options); doc.Save(ArtifactsDir + "HeaderFooter.HeaderFooterOrder.docx"); #if NETFRAMEWORK || NETSTANDARD2_0 Assert.AreEqual("First header\nFirst footer\nSecond header\nSecond footer\nThird header\n" + "Third footer\n", logger.Text.Replace("\r", "")); #else Assert.AreEqual("First header\nFirst footer\nSecond header\nSecond footer\nThird header\n" + "Third footer\n", logger.Text); #endif // Prepare our string builder for assert results without "DifferentFirstPageHeaderFooter" logger.ClearText(); // Remove special first page // The order for this: primary header, default header, primary footer, default footer, even header\footer firstPageSection.PageSetup.DifferentFirstPageHeaderFooter = false; doc.Range.Replace(new Regex("(header|footer)"), "", options); #if NETFRAMEWORK || NETSTANDARD2_0 Assert.AreEqual("Third header\nFirst header\nThird footer\nFirst footer\nSecond header\n" + "Second footer\n", logger.Text.Replace("\r", "")); #else Assert.AreEqual("Third header\nFirst header\nThird footer\nFirst footer\nSecond header\n" + "Second footer\n", logger.Text); #endif }
//ExStart:ShowChangesForHeaderAndFooterOrders public void ShowChangesForHeaderAndFooterOrders() { ReplaceLog logger = new ReplaceLog(); Document doc = new Document(MyDir + "Footer.docx"); Section firstPageSection = doc.FirstSection; FindReplaceOptions options = new FindReplaceOptions { ReplacingCallback = logger }; doc.Range.Replace(new Regex("(header|footer)"), "", options); doc.Save(ArtifactsDir + "FindAndReplace.ShowChangesForHeaderAndFooterOrders.docx"); logger.ClearText(); firstPageSection.PageSetup.DifferentFirstPageHeaderFooter = false; doc.Range.Replace(new Regex("(header|footer)"), "", options); }