Closed Raghvendra0105 closed 1 year ago
Hi. It's actually an expected behavior. ObjectsComparer uses object type to get a list of members to compare. You specify both lists as dynamic, so comparer comparers objects as dynamics (code to get members to compare), but the actual type of the objects is Person (which I assume is not inherited from dynamic).
The following 2 tests pass
[Test]
public void DifferencesInDynamicList()
{
var list1 = new List<dynamic>();
dynamic person1 = new DynamicDictionary();
person1.Name = "Hari";
person1.Age = "21";
list1.Add(person1);
var list2 = new List<dynamic>();
dynamic person2 = new DynamicDictionary();
person2.Name = "Gary";
person2.Age = "21";
list2.Add(person2);
var comparer = new ObjectsComparer.Comparer();
var isEqual = comparer.Compare(list1, list2);
Assert.IsFalse(isEqual);
}
`
[Test]
public void DifferencesInTypedList()
{
var list1 = new List<Person>();
dynamic person1 = new Person();
person1.Name = "Hari";
person1.Age = "21";
list1.Add(person1);
var list2 = new List<Person>();
dynamic person2 = new Person();
person2.Name = "Gary";
person2.Age = "21";
list2.Add(person2);
var comparer = new ObjectsComparer.Comparer();
var isEqual = comparer.Compare(list1, list2);
Assert.IsFalse(isEqual);
}
In the above code, isEqual returned true so no differences were found. But the Name is different for the two objects. List1 and List2 are dynamic types. Am I missing something?
Cheers!