public void CompareTypesDoNotMatch() { var leftObject = new Element() { Content = 32, }; var rightObject = new Element() { Content = "stringvalue", }; ObjectGraphFactory factory = new PublicPropertyObjectGraphFactory(); ObjectGraphComparer comparer = new ObjectGraphComparer(); var left = factory.CreateObjectGraph(leftObject); var right = factory.CreateObjectGraph(rightObject); IEnumerable <ObjectComparisonMismatch> mismatches; bool match = comparer.Compare(left, right, out mismatches); string[] expectedMismatches = new string[] { "ObjectTypesDoNotMatch:Left=RootObject.Content(32) Right=RootObject.Content(stringvalue)", }; string[] actualMismatches = TestHelpers.StringFromMismatches(mismatches); Assert.False(match); Assert.True(actualMismatches.Length == expectedMismatches.Length); for (int index = 0; index < expectedMismatches.Length; index++) { Assert.Equal(expectedMismatches[index], actualMismatches[index]); } }
public void ObjectGraphComparisonStrategyCommentSample() { var l1 = new Sample("SAmplE", null); var l2 = new Sample("1", l1); var l3 = new Sample("TeeST", l2); var l4 = new Sample("2", l3); l1.Child = l4; // l4 -> l3 -> l2 -> l1 -> l4 var r1 = new Sample("sample", null); var r2 = new Sample("1", r1); var r3 = new Sample("TeeeST", r2); var r4 = new Sample("2", r3); r1.Child = r4; var factory = new SampleFactory(); var graph1 = factory.CreateObjectGraph(l4); var graph2 = factory.CreateObjectGraph(r4); IEnumerable <ObjectComparisonMismatch> mismatches; var result = new ObjectGraphComparer().Compare(graph1, graph2, out mismatches); Assert.False(result); Assert.Equal(1, mismatches.Count()); var expected = "ObjectValuesDoNotMatch:Left=Sample.Sample(TeeST) Right=Sample.Sample(TeeeST)"; var actual = TestHelpers.StringFromMismatches(mismatches)[0]; Assert.Equal(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 CompareIncorrectChildCount() { var leftObject = new Element() { Content = new string[] { "String1", "String2", }, }; var rightObject = new Element() { Content = new string[] { "String1", }, }; ObjectGraphFactory factory = new PublicPropertyObjectGraphFactory(); ObjectGraphComparer comparer = new ObjectGraphComparer(); var left = factory.CreateObjectGraph(leftObject); var right = factory.CreateObjectGraph(rightObject); IEnumerable <ObjectComparisonMismatch> mismatches; bool match = comparer.Compare(left, right, out mismatches); string[] expectedMismatches = new string[] { "RightNodeHasFewerChildren:Left=RootObject.Content(System.String[]) Right=RootObject.Content(System.String[])", "MissingRightNode:Left=RootObject.Content.IEnumerable1(String2) Right=Null(Null)", "ObjectValuesDoNotMatch:Left=RootObject.Content.Length(2) Right=RootObject.Content.Length(1)", "ObjectValuesDoNotMatch:Left=RootObject.Content.LongLength(2) Right=RootObject.Content.LongLength(1)", }; string[] actualMismatches = TestHelpers.StringFromMismatches(mismatches); Assert.False(match); Assert.True(actualMismatches.Length == expectedMismatches.Length); for (int index = 0; index < expectedMismatches.Length; index++) { Assert.Equal(expectedMismatches[index], actualMismatches[index]); } }
public void CompareMissingNodes() { var leftObject = new Element() { Name = "Content1", Content = new Element() { Name = "OnlyOnLeft", } }; var rightObject = new Element() { Name = "Content1" }; ObjectGraphFactory factory = new PublicPropertyObjectGraphFactory(); ObjectGraphComparer comparer = new ObjectGraphComparer(); var left = factory.CreateObjectGraph(leftObject); var right = factory.CreateObjectGraph(rightObject); IEnumerable <ObjectComparisonMismatch> mismatches; bool match = comparer.Compare(left, right, out mismatches); string[] expectedMismatches = new string[] { "ObjectValuesDoNotMatch:Left=RootObject.Content(Microsoft.Test.AcceptanceTests.ObjectComparison.Element) Right=RootObject.Content(Null)", "MissingRightNode:Left=RootObject.Content.Content(Null) Right=Null(Null)", "MissingRightNode:Left=RootObject.Content.Name(OnlyOnLeft) Right=Null(Null)", }; string[] actualMismatches = TestHelpers.StringFromMismatches(mismatches); Assert.False(match); Assert.True(actualMismatches.Length == expectedMismatches.Length); for (int index = 0; index < expectedMismatches.Length; index++) { Assert.Equal(expectedMismatches[index], actualMismatches[index]); } }
public void CompareDifferentGraphsDifferentOrder() { var root1 = new GraphNode { Name = "RootNode" }; { var child1 = new GraphNode { Name = "Name", Parent = root1, ObjectValue = "Peter" }; var child4 = new GraphNode { Name = "Value", Parent = root1, ObjectValue = 3 }; // This node should be reported var child2 = new GraphNode { Name = "Value", Parent = root1 }; var child3 = new GraphNode { Name = "Value", Parent = root1 }; var child21 = new GraphNode { Name = "Grandchild", Parent = child2, ObjectValue = 1 }; root1.Children.Add(child1); root1.Children.Add(child4); root1.Children.Add(child2); root1.Children.Add(child3); child2.Children.Add(child21); } var root2 = new GraphNode { Name = "RootNode" }; { var child1 = new GraphNode { Name = "Name", Parent = root2, ObjectValue = "Peter" }; var child2 = new GraphNode { Name = "Value", Parent = root2 }; var child3 = new GraphNode { Name = "Value", Parent = root2 }; var child21 = new GraphNode { Name = "Grandchild", Parent = child2, ObjectValue = 1 }; var child22 = new GraphNode { Name = "Stranger", Parent = child2, ObjectValue = 1 }; // This node should be reported root2.Children.Add(child1); root2.Children.Add(child2); root2.Children.Add(child3); child2.Children.Add(child21); child2.Children.Add(child22); } IEnumerable <ObjectComparisonMismatch> mismatches; var result = new ObjectGraphComparer().Compare(root1, root2, out mismatches); Assert.False(result); var expected = new [] { "RightNodeHasFewerChildren:Left=RootNode(Null) Right=RootNode(Null)", "ObjectValuesDoNotMatch:Left=RootNode.Value(3) Right=RootNode.Value(Null)", "MissingLeftNode:Left=Null(Null) Right=RootNode.Value.Grandchild(1)", "MissingLeftNode:Left=Null(Null) Right=RootNode.Value.Stranger(1)", "MissingRightNode:Left=RootNode.Value(Null) Right=Null(Null)" }; var actual = TestHelpers.StringFromMismatches(mismatches); for (int i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], actual[i]); } }