Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UnitTest1.cs 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using Novacode;
  7. using System.Reflection;
  8. using System.IO;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.Xml.Linq;
  12. using System.IO.Packaging;
  13. namespace UnitTests
  14. {
  15. /// <summary>
  16. /// Summary description for UnitTest1
  17. /// </summary>
  18. [TestClass]
  19. public class UnitTest1
  20. {
  21. // Get the fullpath to the executing assembly.
  22. string directory_executing_assembly;
  23. string directory_documents;
  24. string file_temp = "temp.docx";
  25. const string package_part_document = "/word/document.xml";
  26. public UnitTest1()
  27. {
  28. directory_executing_assembly = Assembly.GetExecutingAssembly().Location;
  29. // The documents directory
  30. List<string> steps = directory_executing_assembly.Split('\\').ToList();
  31. steps.RemoveRange(steps.Count() - 3, 3);
  32. directory_documents = String.Join("\\", steps) + "\\documents\\";
  33. }
  34. [TestMethod]
  35. public void Test_EverybodyHasAHome_Loaded()
  36. {
  37. // Load a document.
  38. using (DocX document = DocX.Load(directory_documents + "EverybodyHasAHome.docx"))
  39. {
  40. // Main document tests.
  41. string document_xml_file = document.mainPart.Uri.OriginalString;
  42. Assert.IsTrue(document.Paragraphs[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  43. Assert.IsTrue(document.Tables[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  44. Assert.IsTrue(document.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  45. Assert.IsTrue(document.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  46. Assert.IsTrue(document.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  47. // header first
  48. Header header_first = document.Headers.first;
  49. string header_first_xml_file = header_first.mainPart.Uri.OriginalString;
  50. Assert.IsTrue(header_first.Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  51. Assert.IsTrue(header_first.Tables[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  52. Assert.IsTrue(header_first.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  53. Assert.IsTrue(header_first.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  54. Assert.IsTrue(header_first.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  55. // header odd
  56. Header header_odd = document.Headers.odd;
  57. string header_odd_xml_file = header_odd.mainPart.Uri.OriginalString;
  58. Assert.IsTrue(header_odd.mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  59. Assert.IsTrue(header_odd.Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  60. Assert.IsTrue(header_odd.Tables[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  61. Assert.IsTrue(header_odd.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  62. Assert.IsTrue(header_odd.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  63. Assert.IsTrue(header_odd.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  64. // header even
  65. Header header_even = document.Headers.even;
  66. string header_even_xml_file = header_even.mainPart.Uri.OriginalString;
  67. Assert.IsTrue(header_even.mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  68. Assert.IsTrue(header_even.Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  69. Assert.IsTrue(header_even.Tables[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  70. Assert.IsTrue(header_even.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  71. Assert.IsTrue(header_even.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  72. Assert.IsTrue(header_even.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  73. // footer first
  74. Footer footer_first = document.Footers.first;
  75. string footer_first_xml_file = footer_first.mainPart.Uri.OriginalString;
  76. Assert.IsTrue(footer_first.mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  77. Assert.IsTrue(footer_first.Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  78. Assert.IsTrue(footer_first.Tables[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  79. Assert.IsTrue(footer_first.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  80. Assert.IsTrue(footer_first.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  81. Assert.IsTrue(footer_first.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  82. // footer odd
  83. Footer footer_odd = document.Footers.odd;
  84. string footer_odd_xml_file = footer_odd.mainPart.Uri.OriginalString;
  85. Assert.IsTrue(footer_odd.mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  86. Assert.IsTrue(footer_odd.Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  87. Assert.IsTrue(footer_odd.Tables[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  88. Assert.IsTrue(footer_odd.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  89. Assert.IsTrue(footer_odd.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  90. Assert.IsTrue(footer_odd.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  91. // footer even
  92. Footer footer_even = document.Footers.even;
  93. string footer_even_xml_file = footer_even.mainPart.Uri.OriginalString;
  94. Assert.IsTrue(footer_even.mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  95. Assert.IsTrue(footer_even.Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  96. Assert.IsTrue(footer_even.Tables[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  97. Assert.IsTrue(footer_even.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  98. Assert.IsTrue(footer_even.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  99. Assert.IsTrue(footer_even.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  100. }
  101. }
  102. [TestMethod]
  103. public void Test_EverybodyHasAHome_Created()
  104. {
  105. // Create a new document.
  106. using (DocX document = DocX.Create("Test.docx"))
  107. {
  108. // Create a Table.
  109. Table t = document.AddTable(3, 3);
  110. t.Design = TableDesign.TableGrid;
  111. // Insert a Paragraph and a Table into the main document.
  112. document.InsertParagraph();
  113. document.InsertTable(t);
  114. // Insert a Paragraph and a Table into every Header.
  115. document.AddHeaders();
  116. document.Headers.odd.InsertParagraph();
  117. document.Headers.odd.InsertTable(t);
  118. document.Headers.even.InsertParagraph();
  119. document.Headers.even.InsertTable(t);
  120. document.Headers.first.InsertParagraph();
  121. document.Headers.first.InsertTable(t);
  122. // Insert a Paragraph and a Table into every Footer.
  123. document.AddFooters();
  124. document.Footers.odd.InsertParagraph();
  125. document.Footers.odd.InsertTable(t);
  126. document.Footers.even.InsertParagraph();
  127. document.Footers.even.InsertTable(t);
  128. document.Footers.first.InsertParagraph();
  129. document.Footers.first.InsertTable(t);
  130. // Main document tests.
  131. string document_xml_file = document.mainPart.Uri.OriginalString;
  132. Assert.IsTrue(document.Paragraphs[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  133. Assert.IsTrue(document.Tables[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  134. Assert.IsTrue(document.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  135. Assert.IsTrue(document.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  136. Assert.IsTrue(document.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(document_xml_file));
  137. // header first
  138. Header header_first = document.Headers.first;
  139. string header_first_xml_file = header_first.mainPart.Uri.OriginalString;
  140. Assert.IsTrue(header_first.Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  141. Assert.IsTrue(header_first.Tables[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  142. Assert.IsTrue(header_first.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  143. Assert.IsTrue(header_first.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  144. Assert.IsTrue(header_first.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_first_xml_file));
  145. // header odd
  146. Header header_odd = document.Headers.odd;
  147. string header_odd_xml_file = header_odd.mainPart.Uri.OriginalString;
  148. Assert.IsTrue(header_odd.mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  149. Assert.IsTrue(header_odd.Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  150. Assert.IsTrue(header_odd.Tables[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  151. Assert.IsTrue(header_odd.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  152. Assert.IsTrue(header_odd.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  153. Assert.IsTrue(header_odd.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_odd_xml_file));
  154. // header even
  155. Header header_even = document.Headers.even;
  156. string header_even_xml_file = header_even.mainPart.Uri.OriginalString;
  157. Assert.IsTrue(header_even.mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  158. Assert.IsTrue(header_even.Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  159. Assert.IsTrue(header_even.Tables[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  160. Assert.IsTrue(header_even.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  161. Assert.IsTrue(header_even.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  162. Assert.IsTrue(header_even.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(header_even_xml_file));
  163. // footer first
  164. Footer footer_first = document.Footers.first;
  165. string footer_first_xml_file = footer_first.mainPart.Uri.OriginalString;
  166. Assert.IsTrue(footer_first.mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  167. Assert.IsTrue(footer_first.Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  168. Assert.IsTrue(footer_first.Tables[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  169. Assert.IsTrue(footer_first.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  170. Assert.IsTrue(footer_first.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  171. Assert.IsTrue(footer_first.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_first_xml_file));
  172. // footer odd
  173. Footer footer_odd = document.Footers.odd;
  174. string footer_odd_xml_file = footer_odd.mainPart.Uri.OriginalString;
  175. Assert.IsTrue(footer_odd.mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  176. Assert.IsTrue(footer_odd.Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  177. Assert.IsTrue(footer_odd.Tables[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  178. Assert.IsTrue(footer_odd.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  179. Assert.IsTrue(footer_odd.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  180. Assert.IsTrue(footer_odd.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_odd_xml_file));
  181. // footer even
  182. Footer footer_even = document.Footers.even;
  183. string footer_even_xml_file = footer_even.mainPart.Uri.OriginalString;
  184. Assert.IsTrue(footer_even.mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  185. Assert.IsTrue(footer_even.Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  186. Assert.IsTrue(footer_even.Tables[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  187. Assert.IsTrue(footer_even.Tables[0].Rows[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  188. Assert.IsTrue(footer_even.Tables[0].Rows[0].Cells[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  189. Assert.IsTrue(footer_even.Tables[0].Rows[0].Cells[0].Paragraphs[0].mainPart.Uri.OriginalString.Equals(footer_even_xml_file));
  190. }
  191. }
  192. [TestMethod]
  193. public void Test_Document_AddImage_FromDisk()
  194. {
  195. using (DocX document = DocX.Create(directory_documents + "test_add_images.docx"))
  196. {
  197. // Add a png to into this document
  198. Novacode.Image png = document.AddImage(directory_documents + "purple.png");
  199. Assert.IsTrue(document.Images.Count == 1);
  200. Assert.IsTrue(Path.GetExtension(png.pr.TargetUri.OriginalString) == ".png");
  201. // Add a tiff into to this document
  202. Novacode.Image tif = document.AddImage(directory_documents + "yellow.tif");
  203. Assert.IsTrue(document.Images.Count == 2);
  204. Assert.IsTrue(Path.GetExtension(tif.pr.TargetUri.OriginalString) == ".tif");
  205. // Add a gif into to this document
  206. Novacode.Image gif = document.AddImage(directory_documents + "orange.gif");
  207. Assert.IsTrue(document.Images.Count == 3);
  208. Assert.IsTrue(Path.GetExtension(gif.pr.TargetUri.OriginalString) == ".gif");
  209. // Add a jpg into to this document
  210. Novacode.Image jpg = document.AddImage(directory_documents + "green.jpg");
  211. Assert.IsTrue(document.Images.Count == 4);
  212. Assert.IsTrue(Path.GetExtension(jpg.pr.TargetUri.OriginalString) == ".jpg");
  213. // Add a bitmap to this document
  214. Novacode.Image bitmap = document.AddImage(directory_documents + "red.bmp");
  215. Assert.IsTrue(document.Images.Count == 5);
  216. // Word does not allow bmp make sure it was inserted as a png.
  217. Assert.IsTrue(Path.GetExtension(bitmap.pr.TargetUri.OriginalString) == ".png");
  218. }
  219. }
  220. [TestMethod]
  221. public void Test_Document_AddImage_FromStream()
  222. {
  223. using (DocX document = DocX.Create(directory_documents + "test_add_images.docx"))
  224. {
  225. // DocX will always insert Images that come from Streams as jpeg.
  226. // Add a png to into this document
  227. Novacode.Image png = document.AddImage(new FileStream(directory_documents + "purple.png", FileMode.Open));
  228. Assert.IsTrue(document.Images.Count == 1);
  229. Assert.IsTrue(Path.GetExtension(png.pr.TargetUri.OriginalString) == ".jpeg");
  230. // Add a tiff into to this document
  231. Novacode.Image tif = document.AddImage(new FileStream(directory_documents + "yellow.tif", FileMode.Open));
  232. Assert.IsTrue(document.Images.Count == 2);
  233. Assert.IsTrue(Path.GetExtension(tif.pr.TargetUri.OriginalString) == ".jpeg");
  234. // Add a gif into to this document
  235. Novacode.Image gif = document.AddImage(new FileStream(directory_documents + "orange.gif", FileMode.Open));
  236. Assert.IsTrue(document.Images.Count == 3);
  237. Assert.IsTrue(Path.GetExtension(gif.pr.TargetUri.OriginalString) == ".jpeg");
  238. // Add a jpg into to this document
  239. Novacode.Image jpg = document.AddImage(new FileStream(directory_documents + "green.jpg", FileMode.Open));
  240. Assert.IsTrue(document.Images.Count == 4);
  241. Assert.IsTrue(Path.GetExtension(jpg.pr.TargetUri.OriginalString) == ".jpeg");
  242. // Add a bitmap to this document
  243. Novacode.Image bitmap = document.AddImage(new FileStream(directory_documents + "red.bmp", FileMode.Open));
  244. Assert.IsTrue(document.Images.Count == 5);
  245. // Word does not allow bmp make sure it was inserted as a png.
  246. Assert.IsTrue(Path.GetExtension(bitmap.pr.TargetUri.OriginalString) == ".jpeg");
  247. }
  248. }
  249. [TestMethod]
  250. public void Test_Tables()
  251. {
  252. using (DocX document = DocX.Load(directory_documents + "Tables.docx"))
  253. {
  254. // There is only one Paragraph at the document level.
  255. Assert.IsTrue(document.Paragraphs.Count() == 13);
  256. // There is only one Table in this document.
  257. Assert.IsTrue(document.Tables.Count() == 1);
  258. // Extract the only Table.
  259. Table t0 = document.Tables[0];
  260. // This table has 12 Paragraphs.
  261. Assert.IsTrue(t0.Paragraphs.Count() == 12);
  262. }
  263. }
  264. [TestMethod]
  265. public void Test_Images()
  266. {
  267. using (DocX document = DocX.Load(directory_documents + "Images.docx"))
  268. {
  269. // Extract Images from Document.
  270. List<Novacode.Image> document_images = document.Images;
  271. // Make sure there are 3 Images in this document.
  272. Assert.IsTrue(document_images.Count() == 3);
  273. // Extract the headers from this document.
  274. Headers headers = document.Headers;
  275. Header header_first = headers.first;
  276. Header header_odd = headers.odd;
  277. Header header_even = headers.even;
  278. #region Header_First
  279. // Extract Images from the first Header.
  280. List<Novacode.Image> header_first_images = header_first.Images;
  281. // Make sure there is 1 Image in the first header.
  282. Assert.IsTrue(header_first_images.Count() == 1);
  283. #endregion
  284. #region Header_Odd
  285. // Extract Images from the odd Header.
  286. List<Novacode.Image> header_odd_images = header_odd.Images;
  287. // Make sure there is 1 Image in the first header.
  288. Assert.IsTrue(header_odd_images.Count() == 1);
  289. #endregion
  290. #region Header_Even
  291. // Extract Images from the odd Header.
  292. List<Novacode.Image> header_even_images = header_even.Images;
  293. // Make sure there is 1 Image in the first header.
  294. Assert.IsTrue(header_even_images.Count() == 1);
  295. #endregion
  296. }
  297. }
  298. [TestMethod]
  299. public void Test_Insert_Picture()
  300. {
  301. // Load test document.
  302. using (DocX document = DocX.Create(directory_documents + "Test.docx"))
  303. {
  304. // Add Headers and Footers into this document.
  305. document.AddHeaders();
  306. document.AddFooters();
  307. document.DifferentFirstPage = true;
  308. document.DifferentOddAndEvenPages = true;
  309. // Add an Image to this document.
  310. Novacode.Image img = document.AddImage(directory_documents + "purple.png");
  311. // Create a Picture from this Image.
  312. Picture pic = img.CreatePicture();
  313. // Main document.
  314. Paragraph p0 = document.InsertParagraph("Hello");
  315. p0.InsertPicture(pic, 3);
  316. // Header first.
  317. Paragraph p1 = document.Headers.first.InsertParagraph("----");
  318. p1.InsertPicture(pic, 2);
  319. // Header odd.
  320. Paragraph p2 = document.Headers.odd.InsertParagraph("----");
  321. p2.InsertPicture(pic, 2);
  322. // Header even.
  323. Paragraph p3 = document.Headers.even.InsertParagraph("----");
  324. p3.InsertPicture(pic, 2);
  325. // Footer first.
  326. Paragraph p4 = document.Footers.first.InsertParagraph("----");
  327. p4.InsertPicture(pic, 2);
  328. // Footer odd.
  329. Paragraph p5 = document.Footers.odd.InsertParagraph("----");
  330. p5.InsertPicture(pic, 2);
  331. // Footer even.
  332. Paragraph p6 = document.Footers.even.InsertParagraph("----");
  333. p6.InsertPicture(pic, 2);
  334. // Save this document.
  335. document.Save();
  336. }
  337. }
  338. [TestMethod]
  339. public void Test_Insert_Hyperlink()
  340. {
  341. // Load test document.
  342. using (DocX document = DocX.Create(directory_documents + "Test.docx"))
  343. {
  344. // Add Headers and Footers into this document.
  345. document.AddHeaders();
  346. document.AddFooters();
  347. document.DifferentFirstPage = true;
  348. document.DifferentOddAndEvenPages = true;
  349. // Add a Hyperlink into this document.
  350. Hyperlink h = document.AddHyperlink("google", new Uri("http://www.google.com"));
  351. // Main document.
  352. Paragraph p0 = document.InsertParagraph("Hello");
  353. p0.InsertHyperlink(h, 3);
  354. // Header first.
  355. Paragraph p1 = document.Headers.first.InsertParagraph("----");
  356. p1.InsertHyperlink(h, 3);
  357. // Header odd.
  358. Paragraph p2 = document.Headers.odd.InsertParagraph("----");
  359. p2.InsertHyperlink(h, 3);
  360. // Header even.
  361. Paragraph p3 = document.Headers.even.InsertParagraph("----");
  362. p3.InsertHyperlink(h, 3);
  363. // Footer first.
  364. Paragraph p4 = document.Footers.first.InsertParagraph("----");
  365. p4.InsertHyperlink(h, 3);
  366. // Footer odd.
  367. Paragraph p5 = document.Footers.odd.InsertParagraph("----");
  368. p5.InsertHyperlink(h, 3);
  369. // Footer even.
  370. Paragraph p6 = document.Footers.even.InsertParagraph("----");
  371. p6.InsertHyperlink(h, 3);
  372. // Save this document.
  373. document.Save();
  374. }
  375. }
  376. [TestMethod]
  377. public void Test_Append_Hyperlink()
  378. {
  379. // Load test document.
  380. using (DocX document = DocX.Create(directory_documents + "Test.docx"))
  381. {
  382. // Add Headers and Footers into this document.
  383. document.AddHeaders();
  384. document.AddFooters();
  385. document.DifferentFirstPage = true;
  386. document.DifferentOddAndEvenPages = true;
  387. // Add a Hyperlink to this document.
  388. Hyperlink h = document.AddHyperlink("google", new Uri("http://www.google.com"));
  389. // Main document.
  390. Paragraph p0 = document.InsertParagraph("----");
  391. p0.AppendHyperlink(h);
  392. Assert.IsTrue(p0.Text == "----google");
  393. // Header first.
  394. Paragraph p1 = document.Headers.first.InsertParagraph("----");
  395. p1.AppendHyperlink(h);
  396. Assert.IsTrue(p1.Text == "----google");
  397. // Header odd.
  398. Paragraph p2 = document.Headers.odd.InsertParagraph("----");
  399. p2.AppendHyperlink(h);
  400. Assert.IsTrue(p2.Text == "----google");
  401. // Header even.
  402. Paragraph p3 = document.Headers.even.InsertParagraph("----");
  403. p3.AppendHyperlink(h);
  404. Assert.IsTrue(p3.Text == "----google");
  405. // Footer first.
  406. Paragraph p4 = document.Footers.first.InsertParagraph("----");
  407. p4.AppendHyperlink(h);
  408. Assert.IsTrue(p4.Text == "----google");
  409. // Footer odd.
  410. Paragraph p5 = document.Footers.odd.InsertParagraph("----");
  411. p5.AppendHyperlink(h);
  412. Assert.IsTrue(p5.Text == "----google");
  413. // Footer even.
  414. Paragraph p6 = document.Footers.even.InsertParagraph("----");
  415. p6.AppendHyperlink(h);
  416. Assert.IsTrue(p6.Text == "----google");
  417. // Save the document.
  418. document.Save();
  419. }
  420. }
  421. [TestMethod]
  422. public void Test_Append_Picture()
  423. {
  424. // Create test document.
  425. using (DocX document = DocX.Create(directory_documents + "Test.docx"))
  426. {
  427. // Add Headers and Footers into this document.
  428. document.AddHeaders();
  429. document.AddFooters();
  430. document.DifferentFirstPage = true;
  431. document.DifferentOddAndEvenPages = true;
  432. // Add an Image to this document.
  433. Novacode.Image img = document.AddImage(directory_documents + "purple.png");
  434. // Create a Picture from this Image.
  435. Picture pic = img.CreatePicture();
  436. // Main document.
  437. Paragraph p0 = document.InsertParagraph();
  438. p0.AppendPicture(pic);
  439. // Header first.
  440. Paragraph p1 = document.Headers.first.InsertParagraph();
  441. p1.AppendPicture(pic);
  442. // Header odd.
  443. Paragraph p2 = document.Headers.odd.InsertParagraph();
  444. p2.AppendPicture(pic);
  445. // Header even.
  446. Paragraph p3 = document.Headers.even.InsertParagraph();
  447. p3.AppendPicture(pic);
  448. // Footer first.
  449. Paragraph p4 = document.Footers.first.InsertParagraph();
  450. p4.AppendPicture(pic);
  451. // Footer odd.
  452. Paragraph p5 = document.Footers.odd.InsertParagraph();
  453. p5.AppendPicture(pic);
  454. // Footer even.
  455. Paragraph p6 = document.Footers.even.InsertParagraph();
  456. p6.AppendPicture(pic);
  457. // Save the document.
  458. document.Save();
  459. }
  460. }
  461. [TestMethod]
  462. public void Test_Move_Picture_Load()
  463. {
  464. // Load test document.
  465. using (DocX document = DocX.Load(directory_documents + "MovePicture.docx"))
  466. {
  467. // Extract the first Picture from the first Paragraph.
  468. Picture picture = document.Paragraphs.First().Pictures.First();
  469. // Move it into the first Header.
  470. Header header_first = document.Headers.first;
  471. header_first.Paragraphs.First().AppendPicture(picture);
  472. // Move it into the even Header.
  473. Header header_even = document.Headers.even;
  474. header_even.Paragraphs.First().AppendPicture(picture);
  475. // Move it into the odd Header.
  476. Header header_odd = document.Headers.odd;
  477. header_odd.Paragraphs.First().AppendPicture(picture);
  478. // Move it into the first Footer.
  479. Footer footer_first = document.Footers.first;
  480. footer_first.Paragraphs.First().AppendPicture(picture);
  481. // Move it into the even Footer.
  482. Footer footer_even = document.Footers.even;
  483. footer_even.Paragraphs.First().AppendPicture(picture);
  484. // Move it into the odd Footer.
  485. Footer footer_odd = document.Footers.odd;
  486. footer_odd.Paragraphs.First().AppendPicture(picture);
  487. // Save this as MovedPicture.docx
  488. document.SaveAs(directory_documents + "MovedPicture.docx");
  489. }
  490. }
  491. [TestMethod]
  492. public void Test_Paragraph_InsertHyperlink()
  493. {
  494. // Create a new document
  495. using (DocX document = DocX.Create("Test.docx"))
  496. {
  497. // Add a Hyperlink to this document.
  498. Hyperlink h = document.AddHyperlink("link", new Uri("http://www.google.com"));
  499. // Simple
  500. Paragraph p1 = document.InsertParagraph("AC");
  501. p1.InsertHyperlink(h); Assert.IsTrue(p1.Text == "linkAC");
  502. p1.InsertHyperlink(h, p1.Text.Length); Assert.IsTrue(p1.Text == "linkAClink");
  503. p1.InsertHyperlink(h, p1.Text.IndexOf("C")); Assert.IsTrue(p1.Text == "linkAlinkClink");
  504. // Difficult
  505. Paragraph p2 = document.InsertParagraph("\tA\tC\t");
  506. p2.InsertHyperlink(h); Assert.IsTrue(p2.Text == "link\tA\tC\t");
  507. p2.InsertHyperlink(h, p2.Text.Length); Assert.IsTrue(p2.Text == "link\tA\tC\tlink");
  508. p2.InsertHyperlink(h, p2.Text.IndexOf("C")); Assert.IsTrue(p2.Text == "link\tA\tlinkC\tlink");
  509. // Contrived
  510. // Add a contrived Hyperlink to this document.
  511. Hyperlink h2 = document.AddHyperlink("\tlink\t", new Uri("http://www.google.com"));
  512. Paragraph p3 = document.InsertParagraph("\tA\tC\t");
  513. p3.InsertHyperlink(h2); Assert.IsTrue(p3.Text == "\tlink\t\tA\tC\t");
  514. p3.InsertHyperlink(h2, p3.Text.Length); Assert.IsTrue(p3.Text == "\tlink\t\tA\tC\t\tlink\t");
  515. p3.InsertHyperlink(h2, p3.Text.IndexOf("C")); Assert.IsTrue(p3.Text == "\tlink\t\tA\t\tlink\tC\t\tlink\t");
  516. }
  517. }
  518. [TestMethod]
  519. public void Test_Paragraph_RemoveHyperlink()
  520. {
  521. // Create a new document
  522. using (DocX document = DocX.Create("Test.docx"))
  523. {
  524. // Add a Hyperlink to this document.
  525. Hyperlink h = document.AddHyperlink("link", new Uri("http://www.google.com"));
  526. // Simple
  527. Paragraph p1 = document.InsertParagraph("AC");
  528. p1.InsertHyperlink(h); Assert.IsTrue(p1.Text == "linkAC");
  529. p1.InsertHyperlink(h, p1.Text.Length); Assert.IsTrue(p1.Text == "linkAClink");
  530. p1.InsertHyperlink(h, p1.Text.IndexOf("C")); Assert.IsTrue(p1.Text == "linkAlinkClink");
  531. // Try and remove a Hyperlink using a negative index.
  532. // This should throw an exception.
  533. try
  534. {
  535. p1.RemoveHyperlink(-1);
  536. Assert.Fail();
  537. }
  538. catch (ArgumentException e) { }
  539. catch (Exception e) { Assert.Fail(); }
  540. // Try and remove a Hyperlink at an index greater than the last.
  541. // This should throw an exception.
  542. try
  543. {
  544. p1.RemoveHyperlink(3);
  545. Assert.Fail();
  546. }
  547. catch (ArgumentException e) {}
  548. catch (Exception e) { Assert.Fail(); }
  549. p1.RemoveHyperlink(0); Assert.IsTrue(p1.Text == "AlinkClink");
  550. p1.RemoveHyperlink(1); Assert.IsTrue(p1.Text == "AlinkC");
  551. p1.RemoveHyperlink(0); Assert.IsTrue(p1.Text == "AC");
  552. }
  553. }
  554. [TestMethod]
  555. public void Test_Paragraph_ReplaceText()
  556. {
  557. // Create a new document
  558. using (DocX document = DocX.Create("Test.docx"))
  559. {
  560. // Simple
  561. Paragraph p1 = document.InsertParagraph("Apple Pear Apple Apple Pear Apple");
  562. p1.ReplaceText("Apple", "Orange"); Assert.IsTrue(p1.Text == "Orange Pear Orange Orange Pear Orange");
  563. p1.ReplaceText("Pear", "Apple"); Assert.IsTrue(p1.Text == "Orange Apple Orange Orange Apple Orange");
  564. p1.ReplaceText("Orange", "Pear"); Assert.IsTrue(p1.Text == "Pear Apple Pear Pear Apple Pear");
  565. // Try and replace text that dosen't exist in the Paragraph.
  566. string old = p1.Text;
  567. p1.ReplaceText("foo", "bar"); Assert.IsTrue(p1.Text.Equals(old));
  568. // Difficult
  569. Paragraph p2 = document.InsertParagraph("Apple Pear Apple Apple Pear Apple");
  570. p2.ReplaceText(" ", "\t"); Assert.IsTrue(p2.Text == "Apple\tPear\tApple\tApple\tPear\tApple");
  571. p2.ReplaceText("\tApple\tApple", ""); Assert.IsTrue(p2.Text == "Apple\tPear\tPear\tApple");
  572. p2.ReplaceText("Apple\tPear\t", ""); Assert.IsTrue(p2.Text == "Pear\tApple");
  573. p2.ReplaceText("Pear\tApple", ""); Assert.IsTrue(p2.Text == "");
  574. }
  575. }
  576. [TestMethod]
  577. public void Test_Paragraph_RemoveText()
  578. {
  579. // Create a new document
  580. using (DocX document = DocX.Create("Test.docx"))
  581. {
  582. // Simple
  583. //<p>
  584. // <r><t>HellWorld</t></r>
  585. //</p>
  586. Paragraph p1 = document.InsertParagraph("HelloWorld");
  587. p1.RemoveText(0, 1); Assert.IsTrue(p1.Text == "elloWorld");
  588. p1.RemoveText(p1.Text.Length - 1, 1); Assert.IsTrue(p1.Text == "elloWorl");
  589. p1.RemoveText(p1.Text.IndexOf("o"), 1); Assert.IsTrue(p1.Text == "ellWorl");
  590. // Try and remove text at an index greater than the last.
  591. // This should throw an exception.
  592. try
  593. {
  594. p1.RemoveText(p1.Text.Length, 1);
  595. Assert.Fail();
  596. }
  597. catch (ArgumentOutOfRangeException e) { }
  598. catch (Exception e) { Assert.Fail(); }
  599. // Try and remove text at a negative index.
  600. // This should throw an exception.
  601. try
  602. {
  603. p1.RemoveText(-1, 1);
  604. Assert.Fail();
  605. }
  606. catch (ArgumentOutOfRangeException e) { }
  607. catch (Exception e) { Assert.Fail(); }
  608. // Difficult
  609. //<p>
  610. // <r><t>A</t></r>
  611. // <r><t>B</t></r>
  612. // <r><t>C</t></r>
  613. //</p>
  614. Paragraph p2 = document.InsertParagraph("A\tB\tC");
  615. p2.RemoveText(0, 1); Assert.IsTrue(p2.Text == "\tB\tC");
  616. p2.RemoveText(p2.Text.Length - 1, 1); Assert.IsTrue(p2.Text == "\tB\t");
  617. p2.RemoveText(p2.Text.IndexOf("B"), 1); Assert.IsTrue(p2.Text == "\t\t");
  618. p2.RemoveText(0, 1); Assert.IsTrue(p2.Text == "\t");
  619. p2.RemoveText(0, 1); Assert.IsTrue(p2.Text == "");
  620. // Contrived 1
  621. //<p>
  622. // <r>
  623. // <t>A</t>
  624. // <t>B</t>
  625. // <t>C</t>
  626. // </r>
  627. //</p>
  628. Paragraph p3 = document.InsertParagraph("");
  629. p3.Xml = XElement.Parse
  630. (
  631. @"<w:p xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
  632. <w:pPr />
  633. <w:r>
  634. <w:rPr />
  635. <w:t>A</w:t>
  636. <w:t>B</w:t>
  637. <w:t>C</w:t>
  638. </w:r>
  639. </w:p>"
  640. );
  641. p3.RemoveText(0, 1); Assert.IsTrue(p3.Text == "BC");
  642. p3.RemoveText(p3.Text.Length - 1, 1); Assert.IsTrue(p3.Text == "B");
  643. p3.RemoveText(0, 1); Assert.IsTrue(p3.Text == "");
  644. // Contrived 2
  645. //<p>
  646. // <r>
  647. // <t>A</t>
  648. // <t>B</t>
  649. // <t>C</t>
  650. // </r>
  651. //</p>
  652. Paragraph p4 = document.InsertParagraph("");
  653. p4.Xml = XElement.Parse
  654. (
  655. @"<w:p xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
  656. <w:pPr />
  657. <w:r>
  658. <w:rPr />
  659. <tab />
  660. <w:t>A</w:t>
  661. <tab />
  662. </w:r>
  663. <w:r>
  664. <w:rPr />
  665. <tab />
  666. <w:t>B</w:t>
  667. <tab />
  668. </w:r>
  669. </w:p>"
  670. );
  671. p4.RemoveText(0, 1); Assert.IsTrue(p4.Text == "A\t\tB\t");
  672. p4.RemoveText(1, 1); Assert.IsTrue(p4.Text == "A\tB\t");
  673. p4.RemoveText(p4.Text.Length - 1, 1); Assert.IsTrue(p4.Text == "A\tB");
  674. p4.RemoveText(1, 1); Assert.IsTrue(p4.Text == "AB");
  675. p4.RemoveText(p4.Text.Length - 1, 1); Assert.IsTrue(p4.Text == "A");
  676. p4.RemoveText(p4.Text.Length - 1, 1); Assert.IsTrue(p4.Text == "");
  677. }
  678. }
  679. [TestMethod]
  680. public void Test_Paragraph_InsertText()
  681. {
  682. // Create a new document
  683. using (DocX document = DocX.Create("Test.docx"))
  684. {
  685. // Simple
  686. //<p>
  687. // <r><t>HelloWorld</t></r>
  688. //</p>
  689. Paragraph p1 = document.InsertParagraph("HelloWorld");
  690. p1.InsertText(0, "-"); Assert.IsTrue(p1.Text == "-HelloWorld");
  691. p1.InsertText(p1.Text.Length, "-"); Assert.IsTrue(p1.Text == "-HelloWorld-");
  692. p1.InsertText(p1.Text.IndexOf("W"), "-"); Assert.IsTrue(p1.Text == "-Hello-World-");
  693. // Try and insert text at an index greater than the last + 1.
  694. // This should throw an exception.
  695. try
  696. {
  697. p1.InsertText(p1.Text.Length + 1, "-");
  698. Assert.Fail();
  699. }
  700. catch (ArgumentOutOfRangeException e) { }
  701. catch (Exception e) { Assert.Fail(); }
  702. // Try and insert text at a negative index.
  703. // This should throw an exception.
  704. try
  705. {
  706. p1.InsertText(-1, "-");
  707. Assert.Fail();
  708. }
  709. catch (ArgumentOutOfRangeException e) { }
  710. catch (Exception e) { Assert.Fail(); }
  711. // Difficult
  712. //<p>
  713. // <r><t>A</t></r>
  714. // <r><t>B</t></r>
  715. // <r><t>C</t></r>
  716. //</p>
  717. Paragraph p2 = document.InsertParagraph("A\tB\tC");
  718. p2.InsertText(0, "-"); Assert.IsTrue(p2.Text == "-A\tB\tC");
  719. p2.InsertText(p2.Text.Length, "-"); Assert.IsTrue(p2.Text == "-A\tB\tC-");
  720. p2.InsertText(p2.Text.IndexOf("B"), "-"); Assert.IsTrue(p2.Text == "-A\t-B\tC-");
  721. p2.InsertText(p2.Text.IndexOf("C"), "-"); Assert.IsTrue(p2.Text == "-A\t-B\t-C-");
  722. // Contrived 1
  723. //<p>
  724. // <r>
  725. // <t>A</t>
  726. // <t>B</t>
  727. // <t>C</t>
  728. // </r>
  729. //</p>
  730. Paragraph p3 = document.InsertParagraph("");
  731. p3.Xml = XElement.Parse
  732. (
  733. @"<w:p xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
  734. <w:pPr />
  735. <w:r>
  736. <w:rPr />
  737. <w:t>A</w:t>
  738. <w:t>B</w:t>
  739. <w:t>C</w:t>
  740. </w:r>
  741. </w:p>"
  742. );
  743. p3.InsertText(0, "-"); Assert.IsTrue(p3.Text == "-ABC");
  744. p3.InsertText(p3.Text.Length, "-"); Assert.IsTrue(p3.Text == "-ABC-");
  745. p3.InsertText(p3.Text.IndexOf("B"), "-"); Assert.IsTrue(p3.Text == "-A-BC-");
  746. p3.InsertText(p3.Text.IndexOf("C"), "-"); Assert.IsTrue(p3.Text == "-A-B-C-");
  747. // Contrived 2
  748. //<p>
  749. // <r>
  750. // <t>A</t>
  751. // <t>B</t>
  752. // <t>C</t>
  753. // </r>
  754. //</p>
  755. Paragraph p4 = document.InsertParagraph("");
  756. p4.Xml = XElement.Parse
  757. (
  758. @"<w:p xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
  759. <w:pPr />
  760. <w:r>
  761. <w:rPr />
  762. <w:t>A</w:t>
  763. <w:t>B</w:t>
  764. <w:t>C</w:t>
  765. </w:r>
  766. </w:p>"
  767. );
  768. p4.InsertText(0, "\t"); Assert.IsTrue(p4.Text == "\tABC");
  769. p4.InsertText(p4.Text.Length, "\t"); Assert.IsTrue(p4.Text == "\tABC\t");
  770. p4.InsertText(p4.Text.IndexOf("B"), "\t"); Assert.IsTrue(p4.Text == "\tA\tBC\t");
  771. p4.InsertText(p4.Text.IndexOf("C"), "\t"); Assert.IsTrue(p4.Text == "\tA\tB\tC\t");
  772. }
  773. }
  774. [TestMethod]
  775. public void Test_Document_Paragraphs()
  776. {
  777. // Load the document 'Paragraphs.docx'
  778. using (DocX document = DocX.Load(directory_documents + "Paragraphs.docx"))
  779. {
  780. // Extract the Paragraphs from this document.
  781. List<Paragraph> paragraphs = document.Paragraphs;
  782. // There should be 3 Paragraphs in this document.
  783. Assert.IsTrue(paragraphs.Count() == 3);
  784. // Extract the 3 Paragraphs.
  785. Paragraph p1 = paragraphs[0];
  786. Paragraph p2 = paragraphs[1];
  787. Paragraph p3 = paragraphs[2];
  788. // Extract their Text properties.
  789. string p1_text = p1.Text;
  790. string p2_text = p2.Text;
  791. string p3_text = p3.Text;
  792. // Test their Text properties against absolutes.
  793. Assert.IsTrue(p1_text == "Paragraph 1");
  794. Assert.IsTrue(p2_text == "Paragraph 2");
  795. Assert.IsTrue(p3_text == "Paragraph 3");
  796. // Its important that each Paragraph knows the PackagePart it belongs to.
  797. document.Paragraphs.ForEach(p => Assert.IsTrue(p.PackagePart.Uri.ToString() == package_part_document));
  798. // Test the saving of the document.
  799. document.SaveAs(file_temp);
  800. }
  801. // Delete the tempory file.
  802. File.Delete(file_temp);
  803. }
  804. [TestMethod]
  805. public void Test_Document_ApplyTemplate()
  806. {
  807. using (MemoryStream documentStream = new MemoryStream())
  808. {
  809. using (DocX document = DocX.Create(documentStream))
  810. {
  811. document.ApplyTemplate(directory_documents + "Template.dotx");
  812. document.Save();
  813. Header firstHeader = document.Headers.first;
  814. Header oddHeader = document.Headers.odd;
  815. Header evenHeader = document.Headers.even;
  816. Footer firstFooter = document.Footers.first;
  817. Footer oddFooter = document.Footers.odd;
  818. Footer evenFooter = document.Footers.even;
  819. Assert.IsTrue(firstHeader.Paragraphs.Count==1, "More than one paragraph in header.");
  820. Assert.IsTrue(firstHeader.Paragraphs[0].Text.Equals("First page header"), "Header isn't retrieved from template.");
  821. Assert.IsTrue(oddHeader.Paragraphs.Count == 1, "More than one paragraph in header.");
  822. Assert.IsTrue(oddHeader.Paragraphs[0].Text.Equals("Odd page header"), "Header isn't retrieved from template.");
  823. Assert.IsTrue(evenHeader.Paragraphs.Count == 1, "More than one paragraph in header.");
  824. Assert.IsTrue(evenHeader.Paragraphs[0].Text.Equals("Even page header"), "Header isn't retrieved from template.");
  825. Assert.IsTrue(firstFooter.Paragraphs.Count == 1, "More than one paragraph in footer.");
  826. Assert.IsTrue(firstFooter.Paragraphs[0].Text.Equals("First page footer"), "Footer isn't retrieved from template.");
  827. Assert.IsTrue(oddFooter.Paragraphs.Count == 1, "More than one paragraph in footer.");
  828. Assert.IsTrue(oddFooter.Paragraphs[0].Text.Equals("Odd page footer"), "Footer isn't retrieved from template.");
  829. Assert.IsTrue(evenFooter.Paragraphs.Count == 1, "More than one paragraph in footer.");
  830. Assert.IsTrue(evenFooter.Paragraphs[0].Text.Equals("Even page footer"), "Footer isn't retrieved from template.");
  831. Paragraph firstParagraph = document.Paragraphs[0];
  832. Assert.IsTrue(firstParagraph.StyleName.Equals("DocXSample"), "First paragraph isn't of style from template.");
  833. }
  834. }
  835. }
  836. }
  837. }