Beispiel #1
0
        public void NullValuesEqual()
        {
            var first = ReferenceHolder <object?> .Strong(null);

            var second = ReferenceHolder <object?> .Weak(null);

            VerifyEqual(first, second);
        }
Beispiel #2
0
        public void SameMixedObjectsEqual()
        {
            var obj   = new object();
            var first = ReferenceHolder <object?> .Strong(obj);

            var second = ReferenceHolder <object?> .Weak(obj);

            VerifyEqual(first, second);
        }
Beispiel #3
0
        public void ExpiredValueNotEqualToNull()
        {
            var strongNull = ReferenceHolder <object?> .Strong(null);

            var weakNull = ReferenceHolder <object?> .Weak(null);

            var expired = ReferenceHolder <object?> .TestAccessor.ReleasedWeak(hashCode : EqualityComparer <object?> .Default.GetHashCode(null !));

            Assert.Equal(strongNull.GetHashCode(), expired.GetHashCode());
            VerifyNotEqual(strongNull, expired);
            VerifyNotEqual(weakNull, expired);
        }
Beispiel #4
0
        public void SameWeakObjectsEqual()
        {
            var obj   = new object();
            var first = ReferenceHolder <object?> .Weak(obj);

            var second = ReferenceHolder <object?> .Weak(obj);

            // 📝 There is no need for a GC.KeepAlive(obj) here. 'VerifyEqual' will produce correct results whether
            // or not the object is still alive. When the object is alive, the equality path is the same as
            // SameStrongObjectsEqual. When the object is not alive, the equality path is the same as
            // ExpiredSameValuesEqual.
            VerifyEqual(first, second);
        }