Implementation of equatable collections
record SimpleRecord
{
public EquatableList<string> List { get; set; }
}
var record1 = new SimpleRecord
{
List = new EquatableList<string> { "a", "b", "c" }
};
var record2 = new SimpleRecord
{
List = new EquatableList<string> { "a", "b", "c" }
};
Assert.That(record1.GetHashCode(), Is.EqualTo(record2.GetHashCode()));
Assert.That(record1, Is.EqualTo(record2));
var record3 = new SimpleRecord
{
List = new EquatableList<string>(StringComparer.OrdinalIgnoreCase)
{ "test", "abc", "8" }
};
var record4 = new SimpleRecord
{
List = new EquatableList<string>(StringComparer.OrdinalIgnoreCase)
{ "TeSt", "aBc", "8" }
};
Assert.That(record1.GetHashCode(), Is.Not.EqualTo(record3.GetHashCode()));
Assert.That(record1, Is.Not.EqualTo(record4));
Assert.That(record3.GetHashCode(), Is.EqualTo(record4.GetHashCode()));
Assert.That(record3, Is.EqualTo(record4));
var record5 = new SimpleRecord
{
List = new EquatableList<string>(StringComparer.OrdinalIgnoreCase)
};
var record6 = new SimpleRecord
{
List = new EquatableList<string>(StringComparer.Ordinal)
};
Assert.That(record5.GetHashCode(), Is.Not.EqualTo(record6.GetHashCode()));
Assert.That(record5, Is.Not.EqualTo(record6));