From 1a8f70bbe5025ce9d4ddb0e0c1cf60fff9467f66 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Fri, 14 Sep 2018 10:16:06 +0200 Subject: [PATCH] Parent child #37. --- Gu.Xml.Tests/XmlTests.ReferenceLoops.cs | 44 +++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Gu.Xml.Tests/XmlTests.ReferenceLoops.cs b/Gu.Xml.Tests/XmlTests.ReferenceLoops.cs index 4a72755..fad2dc5 100644 --- a/Gu.Xml.Tests/XmlTests.ReferenceLoops.cs +++ b/Gu.Xml.Tests/XmlTests.ReferenceLoops.cs @@ -1,4 +1,5 @@ -namespace Gu.Xml.Tests +// ReSharper disable UnusedAutoPropertyAccessor.Global +namespace Gu.Xml.Tests { using System; using NUnit.Framework; @@ -29,7 +30,7 @@ public void LinkedListRootOneNode() } [Test] - public void Infinite() + public void LinkedListInfinite() { var list = new LinkedList(); list.Next = list; @@ -37,10 +38,49 @@ public void Infinite() Assert.AreEqual("Indent level > 1000, reference loop?", exception.Message); } + [Test] + public void ParentNoChild() + { + var actual = Xml.Serialize(new Parent()); + var expected = "" + Environment.NewLine + + ""; + Assert.AreEqual(expected, actual); + } + + [Test] + public void ParentChild() + { + var actual = Xml.Serialize(new Parent { Child = new Child() }); + var expected = "" + Environment.NewLine + + "" + Environment.NewLine + + " " + Environment.NewLine + + ""; + Assert.AreEqual(expected, actual); + } + + [Test] + public void ParentChildInfinite() + { + var parent = new Parent { Child = new Child() }; + parent.Child.Parent = parent; + var exception = Assert.Throws(() => 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; } + } } } } \ No newline at end of file