@@ -14,7 +14,7 @@ public class AbbrTests : HtmlConverterTestBase
14
14
[ TestCase ( @"<abbr title='National Aeronautics and Space Administration'>NASA</abbr>" ) ]
15
15
[ TestCase ( @"<acronym title='National Aeronautics and Space Administration'>NASA</acronym>" ) ]
16
16
[ TestCase ( @"<acronym title='www.nasa.gov'>NASA</acronym>" ) ]
17
- public void ParseAbbr ( string html )
17
+ public void WithTitle_ReturnsFootnote ( string html )
18
18
{
19
19
var elements = converter . Parse ( html ) ;
20
20
Assert . That ( elements , Has . Count . EqualTo ( 1 ) ) ;
@@ -24,17 +24,17 @@ public void ParseAbbr(string html)
24
24
Assert . That ( elements [ 0 ] . InnerText , Is . EqualTo ( "NASA" ) ) ;
25
25
} ) ;
26
26
27
- var noteRef = elements [ 0 ] . GetLastChild < Run > ( ) . GetFirstChild < FootnoteReference > ( ) ;
27
+ var noteRef = elements [ 0 ] . GetLastChild < Run > ( ) ? . GetFirstChild < FootnoteReference > ( ) ;
28
28
Assert . That ( noteRef , Is . Not . Null ) ;
29
29
Assert . Multiple ( ( ) =>
30
30
{
31
- Assert . That ( noteRef . Id . HasValue , Is . EqualTo ( true ) ) ;
31
+ Assert . That ( noteRef . Id ? . HasValue , Is . EqualTo ( true ) ) ;
32
32
Assert . That ( mainPart . FootnotesPart , Is . Not . Null ) ;
33
33
} ) ;
34
34
35
35
Assert . That ( mainPart . FootnotesPart . HyperlinkRelationships . Count ( ) , Is . EqualTo ( 0 ) ) ;
36
36
37
- var fnotes = mainPart . FootnotesPart . Footnotes . Elements < Footnote > ( ) . FirstOrDefault ( f => f . Id . Value == noteRef . Id . Value ) ;
37
+ var fnotes = mainPart . FootnotesPart . Footnotes . Elements < Footnote > ( ) . FirstOrDefault ( f => f . Id ? . Value == noteRef . Id . Value ) ;
38
38
Assert . That ( fnotes , Is . Not . Null ) ;
39
39
}
40
40
@@ -43,7 +43,7 @@ public void ParseAbbr(string html)
43
43
[ TestCase ( @"<abbr title='\\server01\share\NASA.html'>NASA</abbr>" , "file://server01/share/NASA.html" ) ]
44
44
[ TestCase ( @"<abbr title='ftp://server01/share/NASA.html'>NASA</abbr>" , "ftp://server01/share/NASA.html" ) ]
45
45
[ TestCase ( @"<blockquote cite='https://en.wikipedia.org/wiki/NASA'>NASA</blockquote>" , "https://en.wikipedia.org/wiki/NASA" ) ]
46
- public void ParseWithLinks ( string html , string expectedUri )
46
+ public void WithLink_ReturnsFootnote_WithHyperlink ( string html , string expectedUri )
47
47
{
48
48
var elements = converter . Parse ( html ) ;
49
49
Assert . That ( elements , Has . Count . EqualTo ( 1 ) ) ;
@@ -53,18 +53,18 @@ public void ParseWithLinks(string html, string expectedUri)
53
53
Assert . That ( elements [ 0 ] . InnerText , Is . EqualTo ( "NASA" ) ) ;
54
54
} ) ;
55
55
56
- var noteRef = elements [ 0 ] . GetLastChild < Run > ( ) . GetFirstChild < FootnoteReference > ( ) ;
56
+ var noteRef = elements [ 0 ] . GetLastChild < Run > ( ) ? . GetFirstChild < FootnoteReference > ( ) ;
57
57
Assert . That ( noteRef , Is . Not . Null ) ;
58
58
Assert . Multiple ( ( ) =>
59
59
{
60
- Assert . That ( noteRef . Id . HasValue , Is . EqualTo ( true ) ) ;
60
+ Assert . That ( noteRef . Id ? . HasValue , Is . EqualTo ( true ) ) ;
61
61
Assert . That ( mainPart . FootnotesPart , Is . Not . Null ) ;
62
62
} ) ;
63
63
64
- var fnotes = mainPart . FootnotesPart . Footnotes . Elements < Footnote > ( ) . FirstOrDefault ( f => f . Id . Value == noteRef . Id . Value ) ;
64
+ var fnotes = mainPart . FootnotesPart . Footnotes . Elements < Footnote > ( ) . FirstOrDefault ( f => f . Id ? . Value == noteRef . Id . Value ) ;
65
65
Assert . That ( fnotes , Is . Not . Null ) ;
66
66
67
- var link = fnotes . FirstChild . GetFirstChild < Hyperlink > ( ) ;
67
+ var link = fnotes . FirstChild ? . GetFirstChild < Hyperlink > ( ) ;
68
68
Assert . That ( link , Is . Not . Null ) ;
69
69
70
70
var extLink = mainPart . FootnotesPart . HyperlinkRelationships . FirstOrDefault ( r => r . Id == link . Id ) ;
@@ -77,25 +77,25 @@ public void ParseWithLinks(string html, string expectedUri)
77
77
}
78
78
79
79
[ Test ]
80
- public void ParseDocumentEnd ( )
80
+ public void WithPositionToDocumentEnd_ReturnsEndnote ( )
81
81
{
82
82
converter . AcronymPosition = AcronymPosition . DocumentEnd ;
83
83
var elements = converter . Parse ( @"<acronym title='www.nasa.gov'>NASA</acronym>" ) ;
84
84
85
- var noteRef = elements [ 0 ] . GetLastChild < Run > ( ) . GetFirstChild < EndnoteReference > ( ) ;
85
+ var noteRef = elements [ 0 ] . GetLastChild < Run > ( ) ? . GetFirstChild < EndnoteReference > ( ) ;
86
86
Assert . That ( noteRef , Is . Not . Null ) ;
87
87
Assert . Multiple ( ( ) =>
88
88
{
89
- Assert . That ( noteRef . Id . HasValue , Is . EqualTo ( true ) ) ;
89
+ Assert . That ( noteRef . Id ? . HasValue , Is . EqualTo ( true ) ) ;
90
90
Assert . That ( mainPart . EndnotesPart , Is . Not . Null ) ;
91
91
} ) ;
92
92
93
- var fnotes = mainPart . EndnotesPart . Endnotes . Elements < Endnote > ( ) . FirstOrDefault ( f => f . Id . Value == noteRef . Id . Value ) ;
93
+ var fnotes = mainPart . EndnotesPart . Endnotes . Elements < Endnote > ( ) . FirstOrDefault ( f => f . Id ? . Value == noteRef . Id . Value ) ;
94
94
Assert . That ( fnotes , Is . Not . Null ) ;
95
95
}
96
96
97
97
[ Test ]
98
- public void ParseIgnore ( )
98
+ public void Empty_ShouldBeIgnored ( )
99
99
{
100
100
var elements = converter . Parse ( "<abbr></abbr>" ) ;
101
101
Assert . That ( elements , Is . Empty ) ;
@@ -104,72 +104,76 @@ public void ParseIgnore()
104
104
[ TestCase ( "<abbr><a href='www.google.com'>Placeholder</a></abbr>" ) ]
105
105
[ TestCase ( "<abbr>Placeholder</abbr>" ) ]
106
106
[ TestCase ( "<blockquote>Placeholder</blockquote>" ) ]
107
- public void ParseNoDescription ( string html )
107
+ public void WithNoDescription_ReturnsSimpleParagraph ( string html )
108
108
{
109
109
// description nor title was defined - fallback to normal run
110
110
var elements = converter . Parse ( html ) ;
111
111
Assert . That ( elements , Has . Count . EqualTo ( 1 ) ) ;
112
+ Assert . That ( elements , Is . All . TypeOf < Paragraph > ( ) ) ;
112
113
}
113
114
114
115
[ TestCase ( "<abbr title='HyperText Markup Language'>HTML</abbr>" , AcronymPosition . DocumentEnd , Description = "Read existing endnotes references" ) ]
115
116
[ TestCase ( "<abbr title='HyperText Markup Language'>HTML</abbr>" , AcronymPosition . PageEnd , Description = "Read existing footnotes references" ) ]
116
117
[ TestCase ( "<blockquote cite='HyperText Markup Language'>HTML</blockquote>" , AcronymPosition . DocumentEnd , Description = "Read existing endnotes references" ) ]
117
118
[ TestCase ( "<blockquote cite='HyperText Markup Language'>HTML</blockquote>" , AcronymPosition . PageEnd , Description = "Read existing footnotes references" ) ]
118
- public void ParseExistingEndnotes ( string html , AcronymPosition acronymPosition )
119
+ public void WithExistingEndnotes_ReturnsUniqueRefId ( string html , AcronymPosition acronymPosition )
119
120
{
120
121
using var generatedDocument = new MemoryStream ( ) ;
121
122
using ( var buffer = ResourceHelper . GetStream ( "Resources.DocWithNotes.docx" ) )
122
123
buffer . CopyTo ( generatedDocument ) ;
123
124
124
125
generatedDocument . Position = 0L ;
125
126
using WordprocessingDocument package = WordprocessingDocument . Open ( generatedDocument , true ) ;
126
- MainDocumentPart mainPart = package . MainDocumentPart ;
127
- HtmlConverter converter = new ( mainPart ) ;
128
- converter . AcronymPosition = acronymPosition ;
127
+ MainDocumentPart mainPart = package . MainDocumentPart ! ;
128
+ HtmlConverter converter = new ( mainPart )
129
+ {
130
+ AcronymPosition = acronymPosition
131
+ } ;
129
132
130
133
var elements = converter . Parse ( html ) ;
131
134
Assert . That ( elements , Has . Count . EqualTo ( 1 ) ) ;
132
135
133
- FootnoteEndnoteReferenceType noteRef ;
136
+ FootnoteEndnoteReferenceType ? noteRef ;
134
137
135
138
if ( acronymPosition == AcronymPosition . PageEnd )
136
139
{
137
- noteRef = elements [ 0 ] . GetLastChild < Run > ( ) . GetFirstChild < FootnoteReference > ( ) ;
138
- Assert . That ( mainPart . FootnotesPart . Footnotes . Elements < Footnote > ( ) . Select ( fn => fn . Id . Value ) , Is . Unique ) ;
140
+ noteRef = elements [ 0 ] . GetLastChild < Run > ( ) ? . GetFirstChild < FootnoteReference > ( ) ;
141
+ Assert . That ( mainPart . FootnotesPart ! . Footnotes . Elements < Footnote > ( ) . Select ( fn => fn . Id ? . Value ) , Is . Unique ) ;
139
142
}
140
143
else
141
144
{
142
- noteRef = elements [ 0 ] . GetLastChild < Run > ( ) . GetFirstChild < EndnoteReference > ( ) ;
143
- Assert . That ( mainPart . EndnotesPart . Endnotes . Elements < Endnote > ( ) . Select ( fn => fn . Id . Value ) , Is . Unique ) ;
145
+ noteRef = elements [ 0 ] . GetLastChild < Run > ( ) ? . GetFirstChild < EndnoteReference > ( ) ;
146
+ Assert . That ( mainPart . EndnotesPart ! . Endnotes . Elements < Endnote > ( ) . Select ( fn => fn . Id ? . Value ) , Is . Unique ) ;
144
147
}
145
148
146
149
Assert . That ( noteRef , Is . Not . Null ) ;
147
- Assert . That ( noteRef . Id . HasValue , Is . EqualTo ( true ) ) ;
150
+ Assert . That ( noteRef . Id ? . HasValue , Is . EqualTo ( true ) ) ;
148
151
149
- FootnoteEndnoteType note ;
152
+ FootnoteEndnoteType ? note ;
150
153
if ( acronymPosition == AcronymPosition . PageEnd )
151
154
{
152
- note = mainPart . FootnotesPart . Footnotes . Elements < Footnote > ( )
153
- . FirstOrDefault ( fn => fn . Id . Value == noteRef . Id . Value ) ;
155
+ note = mainPart . FootnotesPart ! . Footnotes . Elements < Footnote > ( )
156
+ . FirstOrDefault ( fn => fn . Id ? . Value == noteRef . Id . Value ) ;
154
157
}
155
158
else
156
159
{
157
- note = mainPart . EndnotesPart . Endnotes . Elements < Endnote > ( )
158
- . FirstOrDefault ( fn => fn . Id . Value == noteRef . Id . Value ) ;
160
+ note = mainPart . EndnotesPart ! . Endnotes . Elements < Endnote > ( )
161
+ . FirstOrDefault ( fn => fn . Id ? . Value == noteRef . Id . Value ) ;
159
162
}
163
+ Assert . That ( note , Is . Not . Null ) ;
160
164
Assert . That ( note . InnerText , Is . EqualTo ( " " + "HyperText Markup Language" ) ) ;
161
165
}
162
166
163
167
[ Test ]
164
- public void ParseInline ( )
168
+ public void InsideParagraph_ReturnsMultipleRuns ( )
165
169
{
166
170
var elements = converter . Parse ( @"<p>The
167
171
<abbr title='National Aeronautics and Space Administration'>NASA</abbr>
168
172
is an independent agency of the U.S. federal government responsible for the civil space program, aeronautics research, and space research.</p>" ) ;
169
173
Assert . That ( elements , Has . Count . EqualTo ( 1 ) ) ;
170
174
Assert . Multiple ( ( ) => {
171
175
Assert . That ( elements [ 0 ] , Is . TypeOf ( typeof ( Paragraph ) ) ) ;
172
- Assert . That ( elements [ 0 ] . Elements < Run > ( ) . Count ( ) , Is . GreaterThan ( 2 ) ) ;
176
+ Assert . That ( elements [ 0 ] . Elements < Run > ( ) . Count ( ) , Is . EqualTo ( 6 ) , "3 textual runs + 3 breaks" ) ;
173
177
Assert . That ( elements [ 0 ] . Elements < Run > ( ) . Any ( r => r . HasChild < FootnoteReference > ( ) ) , Is . True ) ;
174
178
} ) ;
175
179
}
0 commit comments