Created
October 17, 2014 04:29
-
-
Save jglinsek/dab7f950a3054cf97301 to your computer and use it in GitHub Desktop.
AngleSharp - clone an element, append it somewhere - the cloned element has a parent but all of it's children do not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void replace_the_parent_with_a_clone_and_the_children_of_the_cloned_parent_should_have_a_parent() | |
{ | |
const string html = @" | |
<html> | |
<body> | |
<div class='parent'> | |
<div class='child'> | |
</div> | |
</div> | |
</body> | |
</html> | |
"; | |
var doc = DocumentBuilder.Html(html); | |
var originalParent = doc.QuerySelector(".parent"); | |
//clone the parent | |
var clonedParent = originalParent.Clone(); | |
clonedParent.Parent.ShouldBe(null); | |
//remove the original parent | |
var grandparent = originalParent.Parent; | |
originalParent.Remove(); | |
originalParent.Parent.ShouldBe(null); | |
grandparent.ShouldNotBe(null); | |
//replace the original parent with the cloned parent | |
grandparent.AppendChild(clonedParent); | |
//the clone itself has the correct parent | |
clonedParent.Parent.ShouldBe(grandparent); | |
//all the children (and grandchildren) of the cloned element have no parent? | |
var cloneElement = (IElement) clonedParent; | |
cloneElement.FirstChild.Parent.ShouldNotBe(null); //FAILS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment