File tree Expand file tree Collapse file tree 4 files changed +33
-18
lines changed
src/DocumentFormat.OpenXml.Framework
test/DocumentFormat.OpenXml.Tests/ofapiTest Expand file tree Collapse file tree 4 files changed +33
-18
lines changed Original file line number Diff line number Diff line change 99using System . Diagnostics . CodeAnalysis ;
1010using System . Globalization ;
1111using System . IO ;
12+ using System . Linq ;
1213using System . Text ;
1314using System . Xml ;
1415
@@ -534,6 +535,21 @@ public override void RemoveAllChildren()
534535
535536 #endregion
536537
538+ /// <summary>
539+ /// Determines if the specified element is a valid child of the current element.
540+ /// </summary>
541+ /// <param name="element">The element to check.</param>
542+ /// <returns>True if the specified element is a valid child; otherwise, false.</returns>
543+ public override bool IsValidChild ( OpenXmlElement element )
544+ {
545+ if ( element is null )
546+ {
547+ return false ;
548+ }
549+
550+ return Metadata . Children . Elements . Any ( el => el . Type . Name . Equals ( element . Metadata . Type . Name ) ) ;
551+ }
552+
537553 /// <summary>
538554 /// Saves all of the current node's children to the specified XmlWriter.
539555 /// </summary>
Original file line number Diff line number Diff line change @@ -1335,14 +1335,9 @@ public bool IsBefore(OpenXmlElement element)
13351335 /// </summary>
13361336 /// <param name="element">The element to check.</param>
13371337 /// <returns>True if the specified element is a valid child; otherwise, false.</returns>
1338- public bool IsValidChild ( OpenXmlElement element )
1338+ public virtual bool IsValidChild ( OpenXmlElement element )
13391339 {
1340- if ( element is null )
1341- {
1342- throw new ArgumentNullException ( nameof ( element ) ) ;
1343- }
1344-
1345- return Metadata . Children . Elements . Any ( el => el . Type . Name . Equals ( element . Metadata . Type . Name ) ) ;
1340+ return false ;
13461341 }
13471342
13481343 private enum ElementOrder
Original file line number Diff line number Diff line change @@ -1009,4 +1009,5 @@ DocumentFormat.OpenXml.OpenXmlPartWriterSettings.Encoding.set -> void
10091009DocumentFormat.OpenXml.OpenXmlPartWriterSettings.OpenXmlPartWriterSettings() -> void
10101010DocumentFormat.OpenXml.OpenXmlPartWriter.OpenXmlPartWriter(DocumentFormat.OpenXml.Packaging.OpenXmlPart! openXmlPart, DocumentFormat.OpenXml.OpenXmlPartWriterSettings! settings) -> void
10111011DocumentFormat.OpenXml.OpenXmlPartWriter.OpenXmlPartWriter(System.IO.Stream! partStream, DocumentFormat.OpenXml.OpenXmlPartWriterSettings! settings) -> void
1012- DocumentFormat.OpenXml.OpenXmlElement.IsValidChild(DocumentFormat.OpenXml.OpenXmlElement! element) -> bool
1012+ virtual DocumentFormat.OpenXml.OpenXmlElement.IsValidChild(DocumentFormat.OpenXml.OpenXmlElement! element) -> bool
1013+ override DocumentFormat.OpenXml.OpenXmlCompositeElement.IsValidChild(DocumentFormat.OpenXml.OpenXmlElement! element) -> bool
Original file line number Diff line number Diff line change @@ -245,11 +245,11 @@ public void GetOrAddFirstChildTest()
245245 public void IsValidChild_ValidChild_ReturnsTrue ( )
246246 {
247247 // Arrange
248- var parentElement = new Paragraph ( ) ;
249- var validChild = new Run ( ) ;
248+ Paragraph parentElement = new ( ) ;
249+ Run validChild = new ( ) ;
250250
251251 // Act
252- var result = parentElement . IsValidChild ( validChild ) ;
252+ bool result = parentElement . IsValidChild ( validChild ) ;
253253
254254 // Assert
255255 Assert . True ( result ) ;
@@ -259,24 +259,27 @@ public void IsValidChild_ValidChild_ReturnsTrue()
259259 public void IsValidChild_InvalidChild_ReturnsFalse ( )
260260 {
261261 // Arrange
262- var parentElement = new Paragraph ( ) ;
263- var invalidChild = new Table ( ) ;
262+ Paragraph parentElement = new ( ) ;
263+ Table invalidChild = new ( ) ;
264264
265265 // Act
266- var result = parentElement . IsValidChild ( invalidChild ) ;
266+ bool result = parentElement . IsValidChild ( invalidChild ) ;
267267
268268 // Assert
269269 Assert . False ( result ) ;
270270 }
271271
272272 [ Fact ]
273- public void IsValidChild_NullChild_ThrowsArgumentNullException ( )
273+ public void IsValidChild_NullChild_ReturnsFalse ( )
274274 {
275275 // Arrange
276- var parentElement = new Paragraph ( ) ;
276+ Paragraph parentElement = new ( ) ;
277277
278- // Act & Assert
279- Assert . Throws < ArgumentNullException > ( ( ) => parentElement . IsValidChild ( null ) ) ;
278+ // Act
279+ bool result = parentElement . IsValidChild ( null ) ;
280+
281+ // Assert
282+ Assert . False ( result ) ;
280283 }
281284 }
282285}
You can’t perform that action at this time.
0 commit comments