forked from antonmihaylov/OpenXmlTemplates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.cs
41 lines (33 loc) · 1.35 KB
/
Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.IO;
using System.Linq;
using NUnit.Framework;
using OpenXMLTemplates;
using OpenXMLTemplates.ControlReplacers;
using OpenXMLTemplates.Documents;
using OpenXMLTemplates.Variables;
namespace OpenXMLTempaltesTest.ControlReplacersTests.RepeatingControlTests
{
public class Tests
{
private TemplateDocument GetDoc => new TemplateDocument(this.CurrentFolder() + "Doc.docx");
private string GetData => File.ReadAllText(this.CurrentFolder() + "data.json");
[Test]
public void TestRepeatingControls()
{
using var doc = GetDoc;
var data = GetData;
var src = new VariableSource();
src.LoadDataFromJson(data);
var replacer = new RepeatingControlReplacer();
replacer.ReplaceAll(doc, src);
doc.SaveAs(this.CurrentFolder() + "result.docx");
Assert.AreEqual(4,
doc.WordprocessingDocument.ContentControls().Count(cc =>
cc.GetContentControlTag() != null && cc.GetContentControlTag().StartsWith("repeatingitem")));
Assert.AreEqual(5,
doc.WordprocessingDocument.ContentControls().Count(cc =>
cc.GetContentControlTag() != null && cc.GetContentControlTag() == "repeating_nestedList"));
doc.WordprocessingDocument.AssertValid();
}
}
}