public void RecordsDoNotUseDuckTyping() { var recordType1 = new MyRecordType { IntProperty = 42, StringProperty = "foo" }; var recordType2 = new ImmutableRecordType { IntProperty = 42, StringProperty = "foo" }; Assert.That(recordType1.Equals(recordType2), Is.False); //The compiler already knows that these two records are different types, //so the following line results in a compiler error. //Assert.That(recordType1 == recordType2, Is.False); }
public void ShallowPropertyEquality() { var firstRecord = new MyRecordType { IntProperty = 42, StringProperty = "foo" }; var secondRecord = new MyRecordType { IntProperty = 42, StringProperty = "foo" }; Assert.That(firstRecord.Equals(secondRecord), Is.EqualTo(true)); Assert.That(firstRecord == secondRecord, Is.True); Assert.That(firstRecord.GetHashCode(), Is.EqualTo(secondRecord.GetHashCode())); //You can mess up Equality and GetHashCode if you try, but //by default they will work like your record type is a value type. }