コード例 #1
0
        public void TestShutDown()
        {
            SendDataDelegate transportDelegate = PacketProcessor;
            var weakTransportDelegateReference = new WeakReference(transportDelegate);
            var transportSink = new BuildEventArgTransportSink(transportDelegate);

            transportSink.ShutDown();

            Assert.NotNull(weakTransportDelegateReference.Target);
            transportDelegate = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // Expected shutdown to null out the sendData delegate, the two garbage collections
            // should have collected the sendDataDelegate causing the weak reference to die.
            Assert.Null(weakTransportDelegateReference.Target);  // " Expected delegate to be dead"
        }