Skip to content

Commit

Permalink
Parent child #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Sep 14, 2018
1 parent 447e7ff commit 1a8f70b
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions Gu.Xml.Tests/XmlTests.ReferenceLoops.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Gu.Xml.Tests
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace Gu.Xml.Tests
{
using System;
using NUnit.Framework;
Expand Down Expand Up @@ -29,18 +30,57 @@ public void LinkedListRootOneNode()
}

[Test]
public void Infinite()
public void LinkedListInfinite()
{
var list = new LinkedList();
list.Next = list;
var exception = Assert.Throws<InvalidOperationException>(() => Xml.Serialize(list));
Assert.AreEqual("Indent level > 1000, reference loop?", exception.Message);
}

[Test]
public void ParentNoChild()
{
var actual = Xml.Serialize(new Parent());
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
"<Parent />";
Assert.AreEqual(expected, actual);
}

[Test]
public void ParentChild()
{
var actual = Xml.Serialize(new Parent { Child = new Child() });
var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
"<Parent>" + Environment.NewLine +
" <Child />" + Environment.NewLine +
"</Parent>";
Assert.AreEqual(expected, actual);
}

[Test]
public void ParentChildInfinite()
{
var parent = new Parent { Child = new Child() };
parent.Child.Parent = parent;
var exception = Assert.Throws<InvalidOperationException>(() => Xml.Serialize(parent));
Assert.AreEqual("Indent level > 1000, reference loop?", exception.Message);
}

public class LinkedList
{
public LinkedList Next { get; set; }
}

public class Parent
{
public Child Child { get; set; }
}

public class Child
{
public Parent Parent { get; set; }
}
}
}
}

0 comments on commit 1a8f70b

Please sign in to comment.