-
Notifications
You must be signed in to change notification settings - Fork 25
/
ConditionalsTests.cs
45 lines (36 loc) · 1.57 KB
/
ConditionalsTests.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
42
43
44
45
using System.IO;
using NUnit.Framework;
using OpenXMLTemplates;
using OpenXMLTemplates.ControlReplacers.DropdownControlReplacers;
using OpenXMLTemplates.Documents;
using OpenXMLTemplates.Variables;
namespace OpenXMLTempaltesTest.ControlReplacersTests.DropdownControlReplacersTests.
ConditionalDropdownControlReplacerTest
{
public class Tests
{
[Test]
public void ReplacedConditionalDropdownContentControls()
{
var filePath = this.CurrentFolder() + "Doc.docx";
using var doc = new TemplateDocument(filePath);
var json = File.ReadAllText(this.CurrentFolder() + "data.json");
var src = new VariableSource();
src.LoadDataFromJson(json);
var replacer = new ConditionalDropdownControlReplacer();
replacer.ReplaceAll(doc, src);
var c1 = doc.WordprocessingDocument.FindContentControl("conditional_isValid");
var c2 = doc.WordprocessingDocument.FindContentControl("conditional_isInvalid");
var c3 = doc.WordprocessingDocument.FindContentControl("conditional_isInvalid_or_isValid");
Assert.NotNull(c1);
Assert.NotNull(c2);
Assert.NotNull(c3);
Assert.AreEqual("THIS IS VALID", c1.GetTextElement().Text);
Assert.AreEqual("THIS IS VALID", c2.GetTextElement().Text);
Assert.AreEqual("THIS IS VALID", c3.GetTextElement().Text);
doc.WordprocessingDocument.AssertValid();
doc.SaveAs(this.CurrentFolder() + "result.docx");
doc.Close();
}
}
}