예제 #1
0
        public void ObjectEquality()
        {
            IEqualityComparer<IObject> comparer = new ObjectEqualityComparer();
            var m1 = new Mock<IObject>(MockBehavior.Strict);
            m1.SetupGet(o => o.Id).Returns(1L);

            var m2 = new Mock<IObject>(MockBehavior.Strict);
            m2.SetupGet(o => o.Id).Returns(2L);

            Assert.That(comparer.GetHashCode(null), Is.EqualTo(0));
            Assert.That(comparer.GetHashCode(m1.Object), Is.EqualTo(1L));

            Assert.That(comparer.Equals(null, null), Is.True);
            Assert.That(comparer.Equals(m1.Object, null), Is.False);
            Assert.That(comparer.Equals(m1.Object, m2.Object), Is.False);
            Assert.That(comparer.Equals(m1.Object, m1.Object), Is.True);
        }
예제 #2
0
        // Equals method for the comparer itself.
        public override bool Equals(Object obj)
        {
            ObjectEqualityComparer <T> comparer = obj as ObjectEqualityComparer <T>;

            return(comparer != null);
        }