public void ByDefaultThrowsOnUnknownComparisonStrategy() { var root = new GraphNode { Name = "Root", ComparisonStrategy = new IgnoreCaseComparisonStrategy() }; Assert.Throws <XmlException>(() => TestHelpers.XmlCodecRoundtrip(root)); }
public void EncodesAndDecodesChar() { var graphName = "MyGraph"; var graphValue = 'a'; var graph = new GraphNode { Name = graphName, ObjectValue = graphValue }; var actual = TestHelpers.XmlCodecRoundtrip(graph); Assert.Equal(graphValue.ToString(), actual.ObjectValue); }
public void WorksWithFileStream() { var p1 = new Person("John"); p1.Children.Add(new Person("Peter")); p1.Children.Add(new Person("Mary")); var factory = new PublicPropertyObjectGraphFactory(); var graph1 = factory.CreateObjectGraph(p1); var actual = TestHelpers.XmlCodecFileRoundtrip(graph1); var expected = TestHelpers.XmlCodecRoundtrip(graph1); Assert.True(new ObjectGraphComparer().Compare(expected, actual)); }
public void IfSetDoesNotThrowOnUnknownComparisonStrategy() { var root = new GraphNode { Name = "Root", ComparisonStrategy = new IgnoreCaseComparisonStrategy() }; var decoded = TestHelpers.XmlCodecRoundtrip(root, false); IEnumerable <ObjectComparisonMismatch> mismatches; var result = new ObjectGraphComparer().Compare(root, decoded, out mismatches); Assert.False(result); Assert.Equal(1, mismatches.Count()); var expected = "ComparisonStrategiesDoNotMatch:Left=Root(Null) Right=Root(Null)"; var actual = TestHelpers.StringFromMismatches(mismatches)[0]; Assert.Equal(expected, actual); }
public void RestoresComparisonStrategies() { var root1 = new GraphNode { Name = "RootNode" }; { var child1 = new GraphNode { Name = "Name", Parent = root1, ObjectValue = "Peter" }; var child2 = new GraphNode { Name = "Value", Parent = root1 }; var child3 = new GraphNode { Name = "Value", Parent = root1, ObjectValue = "MILK" }; var child21 = new GraphNode { Name = "Grandchild", Parent = child2, ObjectValue = "TEst" }; root1.Children.Add(child1); root1.Children.Add(child2); root1.Children.Add(child3); child2.Children.Add(child21); child3.ComparisonStrategy = new IgnoreCaseComparisonStrategy(); child21.ComparisonStrategy = new IgnoreCaseComparisonStrategy(); } var root2 = new GraphNode { Name = "RootNode" }; { var child1 = new GraphNode { Name = "Name", Parent = root2, ObjectValue = "Peter" }; var child3 = new GraphNode { Name = "Value", Parent = root2, ObjectValue = "Milk" }; var child2 = new GraphNode { Name = "Value", Parent = root2 }; var child21 = new GraphNode { Name = "Grandchild", Parent = child2, ObjectValue = "test" }; root2.Children.Add(child1); root2.Children.Add(child3); root2.Children.Add(child2); child2.Children.Add(child21); child3.ComparisonStrategy = new IgnoreCaseComparisonStrategy(); child21.ComparisonStrategy = new IgnoreCaseComparisonStrategy(); } // Normally those object graphs are equal Assert.True(new ObjectGraphComparer().Compare(root1, root2)); var strategies = new HashSet <ObjectGraphComparisonStrategy>(); strategies.Add(new IgnoreCaseComparisonStrategy()); var decoded1 = TestHelpers.XmlCodecRoundtrip(root1, strategies); Assert.True(new ObjectGraphComparer().Compare(decoded1, root2)); }
public void EncodesAndComparesCyclicObjectGraphs() { var root1 = new GraphNode { Name = "RootNode" }; { var child1 = new GraphNode { Name = "Name", Parent = root1, ObjectValue = "Peter" }; var child2 = new GraphNode { Name = "Value", Parent = root1 }; var child3 = new GraphNode { Name = "Value", Parent = root1, ObjectValue = "Milk" }; var child21 = new GraphNode { Name = "Grandchild", Parent = child2, ObjectValue = "test" }; root1.Children.Add(child1); root1.Children.Add(child2); root1.Children.Add(child3); child2.Children.Add(child21); child21.Children.Add(root1); } var root2 = new GraphNode { Name = "RootNode" }; { var child1 = new GraphNode { Name = "Name", Parent = root2, ObjectValue = "Peter" }; var child3 = new GraphNode { Name = "Value", Parent = root2, ObjectValue = "Milk" }; var child2 = new GraphNode { Name = "Value", Parent = root2 }; var child21 = new GraphNode { Name = "Grandchild", Parent = child2, ObjectValue = "test" }; root2.Children.Add(child1); root2.Children.Add(child3); root2.Children.Add(child2); child2.Children.Add(child21); child21.Children.Add(root2); } // Normally those object graphs are equal Assert.True(new ObjectGraphComparer().Compare(root1, root2)); var decoded1 = TestHelpers.XmlCodecRoundtrip(root1); var decoded2 = TestHelpers.XmlCodecRoundtrip(root2); Assert.True(new ObjectGraphComparer().Compare(decoded1, decoded2)); }