Exemplo n.º 1
0
 public void OnDispose_DisposerDisposesContainedInstances()
 {
     var instance = new DisposeTracker();
     var disposer = new Disposer();
     disposer.AddInstanceForDisposal(instance);
     Assert.IsFalse(instance.IsDisposed);
     disposer.Dispose();
     Assert.IsTrue(instance.IsDisposed);
 }
Exemplo n.º 2
0
        public void DisposerDisposesContainedInstances_InReverseOfOrderAdded()
        {
            DisposeTracker lastDisposed = null;

            var instance1 = new DisposeTracker();
            instance1.Disposing += (s, e) => lastDisposed = instance1;
            var instance2 = new DisposeTracker();
            instance2.Disposing += (s, e) => lastDisposed = instance2;

            var disposer = new Disposer();

            disposer.AddInstanceForDisposal(instance1);
            disposer.AddInstanceForDisposal(instance2);

            disposer.Dispose();

            Assert.AreSame(instance1, lastDisposed);
        }