static void Main(string[] args) { try { // Create object var c1 = new CircularReference("C1"); var c11 = new CircularReference("C11").SetParent(c1); var c111 = new CircularReference("C111").SetParent(c11); var c112 = new CircularReference("C112").SetParent(c11); var c12 = new CircularReference("C12").SetParent(c1); var c121 = new CircularReference("C121").SetParent(c12); var c1211 = new CircularReference("C1211").SetParent(c121); var c1212 = new CircularReference("C1212").SetParent(c121); // Serialize object ////string json = StandardSerialization(c1); string json = CustomSerialization(c1); // Output serialized object System.IO.File.WriteAllText("c:\\temp\\Output.json", json); Console.WriteLine(json); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public void ShouldAllowCircularHeirarchies() { var grandparent = new CircularReference() { Id = 1, Outer = null }; var parent = new CircularReference() { Id = 2, Outer = grandparent }; var child = new CircularReference() { Id = 3, Outer = parent }; grandparent.Inner = parent; parent.Inner = child; this._context.Add(grandparent); this._context.Commit(); var circularReferences = this._context.AsQueryable <CircularReference>(); circularReferences.Count().Should().Be(3); circularReferences.Single(x => x.Id == 1).Inner.Should().BeSameAs(parent); circularReferences.Single(x => x.Id == 2).Inner.Should().BeSameAs(child); circularReferences.Single(x => x.Id == 3).Inner.Should().BeNull(); circularReferences.Single(x => x.Id == 3).Outer.Should().BeSameAs(parent); circularReferences.Single(x => x.Id == 2).Outer.Should().BeSameAs(grandparent); circularReferences.Single(x => x.Id == 1).Outer.Should().BeNull(); }
public void Equals_True_CircularReference_DoubleNavigation() { // Arrange var componentUnderTest = new FieldValueEqualityComparer(); FieldValueEqualityComparer.SetAssembliesWithTypesToUseValueSemanticsOn(new[] { typeof(SimplePoco).Assembly }); var parent1 = new CircularReference(); var child1 = new CircularReference(); var other1 = new CircularReference(); parent1.Child = child1; child1.Parent = parent1; child1.OtheReference = other1; other1.Child = parent1; var parent2 = new CircularReference(); var child2 = new CircularReference(); var other2 = new CircularReference(); parent2.Child = child2; child2.Parent = parent2; child2.OtheReference = other2; other2.Child = parent2; // Act var actual = componentUnderTest.Equals(parent1, parent2); // Assert Assert.AreEqual(true, actual); }
public void Equals_False_CircularReference() { // Arrange var componentUnderTest = new FieldValueEqualityComparer(); FieldValueEqualityComparer.SetAssembliesWithTypesToUseValueSemanticsOn(new[] { typeof(SimplePoco).Assembly }); var parent1 = new CircularReference(); var child1 = new CircularReference(); parent1.Child = child1; child1.Parent = parent1; child1.MyString = "test"; var parent2 = new CircularReference(); var child2 = new CircularReference(); parent2.Child = child2; child2.Parent = parent2; // Act var actual = componentUnderTest.Equals(parent1, parent2); // Assert Assert.AreEqual(false, actual); }
public void should_not_serialize_circular_references() { var graph = new CircularReference { Value = new CircularReferenceNode { Value1 = "hai" } }; graph.Value.Value2 = graph; var json = Bender.Serializer.Create().SerializeJson(graph); var result = json.ParseJson().JsonRoot().JsonObjectField("Value"); result.JsonStringField("Value1").Value.ShouldEqual("hai"); result.JsonFieldExists("Value2").ShouldBeFalse(); }
public void should_not_serialize_circular_references() { var graph = new CircularReference { Value = new CircularReferenceNode { Value1 = "hai" } }; graph.Value.Value2 = graph; var xml = Bender.Serializer.Create().SerializeXml(graph); var root = xml.ParseXml().Element("CircularReference").Element("Value"); root.Element("Value1").Value.ShouldEqual("hai"); root.Element("Value2").ShouldBeNull(); }
public void should_not_allow_circular_references() { var graph = new CircularReference { Value = new CircularReferenceNode { Value1 = "hai" } }; graph.Value.Value2 = graph; Serialize.Json(graph).ShouldEqual("{\"Value\":{\"Value1\":\"hai\"}}"); }
public void SerializeCircularReference() { var obj = new CircularReference(); obj.Child1 = new CircularReference { Child1 = obj, Child2 = obj }; Action action = () => RoundtripSerializer.Serialize(new StringWriter(), obj, typeof(CircularReference)); action.ShouldNotThrow(); }
public void should_not_allow_circular_references() { var graph = new CircularReference { Value = new CircularReferenceNode { Value1 = "hai" } }; graph.Value.Value2 = new List <CircularReference> { graph }; Serialize.Xml(graph).ShouldEqual(Xml.Declaration + "<CircularReference><Value><Value1>hai</Value1><Value2 /></Value></CircularReference>"); }
public void should_not_allow_circular_references() { var graph = new CircularReference { Value = new CircularReferenceNode { Value1 = "hai" } }; graph.Value.Value2 = new Dictionary <string, CircularReference> { { "item", graph } }; Serialize.Json(graph).ShouldEqual("{\"Value\":{\"Value1\":\"hai\",\"Value2\":{}}}"); }
public void ShouldAllowCircularHeirarchies() { var grandparent = new CircularReference() {Id = 1, Outer = null}; var parent = new CircularReference() {Id = 2, Outer = grandparent}; var child = new CircularReference() {Id = 3, Outer = parent}; grandparent.Inner = parent; parent.Inner = child; this._context.Add(grandparent); this._context.Commit(); var circularReferences = this._context.AsQueryable<CircularReference>(); circularReferences.Count().Should().Be(3); circularReferences.Single(x => x.Id == 1).Inner.Should().BeSameAs(parent); circularReferences.Single(x => x.Id == 2).Inner.Should().BeSameAs(child); circularReferences.Single(x => x.Id == 3).Inner.Should().BeNull(); circularReferences.Single(x => x.Id == 3).Outer.Should().BeSameAs(parent); circularReferences.Single(x => x.Id == 2).Outer.Should().BeSameAs(grandparent); circularReferences.Single(x => x.Id == 1).Outer.Should().BeNull(); }