Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="unused"></param>
 public void Execute(object unused)
 {
     action?.Invoke();
 }