/// <summary> ///A test for Reference ///</summary> public void ReferenceTestHelper <V>(V v) where V : class { WeakValueRef <V> target1 = WeakValueRef <V> .Create(v); WeakValueRef <V> target2 = WeakValueRef <V> .Create(v); Assert.IsTrue(object.ReferenceEquals(target1.Reference, target1.Reference)); Assert.IsFalse(object.ReferenceEquals(target1.Reference, target2.Reference)); }
/// <summary> ///A test for IsGarbage ///</summary> public void IsGarbageTestHelper <V>(V v) where V : class { WeakValueRef <V> target = WeakValueRef <V> .Create(v); Assert.IsFalse(target.IsGarbage); ((WeakReference)target.Reference).Target = null; Assert.IsTrue(target.IsGarbage); }
/// <summary> ///A test for GetValue ///</summary> public void GetValueTestHelper <V>(V v) where V : class { var target = WeakValueRef <V> .Create(null); V stored; Assert.IsTrue(target.GetValue(out stored)); Assert.IsTrue(null == stored); target = WeakValueRef <V> .Create(v); Assert.IsTrue(target.GetValue(out stored)); Assert.AreEqual(v, stored); }
/// <summary> ///A test for Equals ///</summary> public void EqualsTest1Helper <E>(E a) where E : class { WeakValueRef <E> target = WeakValueRef <E> .Create(a); object obj = null; // TODO: Initialize to an appropriate value Assert.IsFalse(target.Equals(obj)); obj = new object(); Assert.IsFalse(target.Equals(obj)); obj = WeakValueRef <E> .Create(a); Assert.IsTrue(target.Equals(obj)); }
/// <summary> ///A test for Equals ///</summary> public void EqualsTestHelper <E>(E a, E b) where E : class { WeakValueRef <E> target = WeakValueRef <E> .Create(a); WeakValueRef <E> other = WeakValueRef <E> .Create(b); Assert.IsFalse(target.Equals(other)); other = WeakValueRef <E> .Create(a); Assert.IsTrue(target.Equals(other)); ((WeakReference)target.Reference).Target = null; Assert.IsTrue(target.Equals(target)); ((WeakReference)other.Reference).Target = null; Assert.IsFalse(target.Equals(other)); }