-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageTests.cs
More file actions
134 lines (101 loc) · 3.54 KB
/
Copy pathUsageTests.cs
File metadata and controls
134 lines (101 loc) · 3.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
public class UsageTests
{
[Test]
public async Task Substitution()
{
using var template = DocxTemplateBuilder.Build(
"""
// begin-snippet: SubstitutionInput
Invoice {{ Number }}
Customer: {{ Customer.Name }}
Total: {{ Total }} {{ Currency }}
// end-snippet
""");
#region Substitution
var store = new TemplateStore();
store.RegisterDocxTemplate<Invoice>(template);
using var stream = new MemoryStream();
await store.Render(SampleData.Invoice(), stream);
#endregion
stream.Position = 0;
await Verify(stream, "docx");
}
[Test]
public async Task SubstitutionFromNonMemoryStream()
{
using var template = DocxTemplateBuilder.Build(
"""
Invoice {{ Number }}
Customer: {{ Customer.Name }}
Total: {{ Total }} {{ Currency }}
""");
// Wrap in BufferedStream so the registration hits the non-MemoryStream path
using var wrapped = new BufferedStream(template);
var store = new TemplateStore();
store.RegisterDocxTemplate<Invoice>(wrapped);
using var stream = new MemoryStream();
await store.Render(SampleData.Invoice(), stream);
stream.Position = 0;
await Verify(stream, "docx");
}
[Test]
public async Task Markdown()
{
var markdownSource =
"""
<!-- begin-snippet: MarkdownTemplate(lang=handlebars) -->
# {{ Report.Title }}
*Prepared by **{{ Report.Author }}** on {{ Report.Date }}*
## Summary
{{ Report.Summary }}
## Findings
| Area | Status | Owner |
| --- | --- | --- |
{% for finding in Report.Findings -%}
| {{ finding.Area }} | {{ finding.Status }} | {{ finding.Owner }} |
{% endfor %}
## Action items
{% for item in Report.Actions %}
1. **{{ item.Title }}** — {{ item.Detail }}
{% endfor %}
{% if Report.HasRisks %}
> ⚠ Outstanding risks remain. See appendix for mitigation plan.
{% else %}
> No outstanding risks.
{% endif %}
<!-- end-snippet -->
""";
#region Markdown
using var brandDocx = DocxTemplateBuilder.Build();
var reportModel = SampleData.Report();
var store = new TemplateStore();
store.RegisterMarkdownTemplate<ReportContext>(
markdownSource,
styleSource: brandDocx);
using var stream = new MemoryStream();
await store.Render(reportModel, stream);
#endregion
stream.Position = 0;
await Verify(stream, "docx");
}
[Test]
public async Task MarkdownFromNonMemoryStream()
{
var markdownSource =
"""
# {{ Report.Title }}
{{ Report.Summary }}
""";
using var styleSource = DocxTemplateBuilder.Build();
// Wrap in BufferedStream so the registration hits the non-MemoryStream path
using var wrapped = new BufferedStream(styleSource);
var store = new TemplateStore();
store.RegisterMarkdownTemplate<ReportContext>(
markdownSource,
styleSource: wrapped);
using var stream = new MemoryStream();
await store.Render(SampleData.Report(), stream);
stream.Position = 0;
await Verify(stream, "docx");
}
}