public void IsValidAsLongAsTargetIsAlive() { MockDelegateTarget mockDelegateTarget = new MockDelegateTarget(); var weakDelegate = new WeakDelegate<Action<object>>(mockDelegateTarget.DelegateMethod); GC.Collect(); Assert.IsTrue(weakDelegate.IsAlive); object dummyParameter = new object(); weakDelegate.Invoke(dummyParameter); Assert.IsTrue(mockDelegateTarget.DelegateCalled); Assert.AreSame(dummyParameter, mockDelegateTarget.DelegateParameter); }
public void IsAlwaysValidForStaticMethods() { var weakDelegate = new WeakDelegate<Action<object>>(MockStaticDelegateTarget.DelegateMethod); GC.Collect(); Assert.IsTrue(weakDelegate.IsAlive); MockStaticDelegateTarget.Clear(); object dummyParameter = new object(); weakDelegate.Invoke(dummyParameter); Assert.IsTrue(MockStaticDelegateTarget.DelegateCalled); Assert.AreSame(dummyParameter, MockStaticDelegateTarget.DelegateParameter); }
public void IsAlwaysValidForStaticMethods() { var weakDelegate = new WeakDelegate <Action <object> >(MockStaticDelegateTarget.DelegateMethod); GC.Collect(); Assert.IsTrue(weakDelegate.IsAlive); MockStaticDelegateTarget.Clear(); object dummyParameter = new object(); weakDelegate.Invoke(dummyParameter); Assert.IsTrue(MockStaticDelegateTarget.DelegateCalled); Assert.AreSame(dummyParameter, MockStaticDelegateTarget.DelegateParameter); }
public void IsValidAsLongAsTargetIsAlive() { MockDelegateTarget mockDelegateTarget = new MockDelegateTarget(); var weakDelegate = new WeakDelegate <Action <object> >(mockDelegateTarget.DelegateMethod); GC.Collect(); Assert.IsTrue(weakDelegate.IsAlive); object dummyParameter = new object(); weakDelegate.Invoke(dummyParameter); Assert.IsTrue(mockDelegateTarget.DelegateCalled); Assert.AreSame(dummyParameter, mockDelegateTarget.DelegateParameter); }
/// <summary> /// /// </summary> /// <param name="unused"></param> public void Execute(object unused) { action?.Invoke(); }