예제 #1
0
        /// <summary>
        ///A test for GetValue
        ///</summary>
        void GetValueTestHelper <E, T>(E e, T tail)
            where E : class
            where T : ITrashable
        {
            KeySegment <E, T> target =
                new KeySegment <E, T>()
            {
                _elementReference = new WeakKey <E> {
                    _elementReference = new WeakReference(e)
                },
                _tail = tail
            }
            ;
            E value = null; // TODO: Initialize to an appropriate value

            Assert.IsTrue(target.GetValue(out value, true));
            Assert.AreEqual(e, value);

            ((WeakReference)target._elementReference._elementReference).Target = null;

            Assert.IsFalse(target.GetValue(out value, true));

            ((WeakReference)target._elementReference._elementReference).Target = WeakKey <E> .NullValue;
            Assert.IsTrue(target.GetValue(out value, true));
            Assert.AreEqual(null, value);

            target._elementReference._elementReference = e;
            Assert.IsTrue(target.GetValue(out value, false));
            Assert.AreEqual(e, value);
        }
예제 #2
0
        /// <summary>
        ///A test for SetValue
        ///</summary>
        void SetValueTestHelper <E, T>(E e, T tail)
            where E : class
            where T : ITrashable
        {
            KeySegment <E, T> target =
                new KeySegment <E, T>()
            {
                _elementReference = new WeakKey <E>
                {
                    _elementReference = new WeakReference(null)
                },
                _tail = tail
            }
            ;

            target.SetValue(e, true);

            E value = null;

            Assert.IsTrue(target.GetValue(out value, true));
            Assert.AreEqual(e, value);

            target.SetValue(null, true);

            Assert.IsTrue(target.GetValue(out value, true));
            Assert.AreEqual(null, value);

            target.SetValue(e, false);

            Assert.IsTrue(target.GetValue(out value, false));
            Assert.AreEqual(e, value);
        }