예제 #1
0
        public void DefaultComparerReturnsFalseIfObjectsAreNotSame()
        {
            var comparer = ObjectReferenceComparer <ObjRefComparerTestStub> .Default;

            var x = new ObjRefComparerTestStub(1);
            var y = new ObjRefComparerTestStub(2);

            bool result = comparer.Equals(x, y);

            Assert.IsFalse(result);
        }
예제 #2
0
        public void DefaultComparerReturnsTrueIfOjectsAreSameInstance()
        {
            var comparer = ObjectReferenceComparer <ObjRefComparerTestStub> .Default;

            var x = new ObjRefComparerTestStub(1);
            var y = x;

            bool result = comparer.Equals(x, y);

            Assert.IsTrue(result);
        }
예제 #3
0
        public void ComparerReturnsFalseIfObjectsAreNotSameInstanceIgnoringEquatableImplementation()
        {
            var comparer = new ObjectReferenceComparer <ObjRefComparerTestStub>();

            var x = new ObjRefComparerTestStub(1);
            var y = new ObjRefComparerTestStub(1);

            bool comparerResult = comparer.Equals(x, y);
            bool equalsResult   = x.Equals(y);

            Assert.IsFalse(comparerResult);
            Assert.IsTrue(equalsResult);
        }
예제 #4
0
        public void DefaultComparerReturnsFalseIfObjectsAreNotSameInstanceIgnoringEqualsOverride()
        {
            var comparer = ObjectReferenceComparer <ObjRefComparerTestStub> .Default;

            var x = new ObjRefComparerTestStub(1);
            var y = new ObjRefComparerTestStub(1);

            bool comparerResult = comparer.Equals(x, y);
            bool equalsResult   = x.Equals((object)y);

            Assert.IsFalse(comparerResult);
            Assert.IsTrue(equalsResult);
        }
예제 #5
0
        public void ObjectReferenceComparerGetHashCodeReturnsSameHashCodeForObject()
        {
            var comparer = ObjectReferenceComparer <IEquatable <ObjRefComparerTestStub> > .Default;

            IEquatable <ObjRefComparerTestStub> obj = new ObjRefComparerTestStub(2);

            //get the HashCode 2000 times to confirm it is consistent for lifetime of the object
            HashSet <int> hashes = new HashSet <int>();

            for (int i = 0; i < 2000; i++)
            {
                hashes.Add(comparer.GetHashCode(obj));
            }

            Assert.AreEqual(1, hashes.Count);
        }