Exemple #1
0
        public void UnregisterTrackedTypeStopsTracking()
        {
            DisposableTracker.RegisterTrackedType(typeof(TestDisposable));
            DisposableTracker.RegisterTrackedType(typeof(ReferenceCounted));
            using (var t = new TestDisposable())
                using (var t2 = new ReferenceCounted())
                {
                    //Confirm both items tracked
                    int trackedItems = 0;
                    DisposableTracker.EnumerateTrackedInstances((td) => trackedItems++);
                    Assert.AreEqual(2, trackedItems);
                    trackedItems = 0;

                    //Remove one type, and check only one instance being tracked
                    DisposableTracker.UnregisterTrackedType(typeof(TestDisposable));
                    DisposableTracker.EnumerateTrackedInstances((td) => trackedItems++);
                    Assert.AreEqual(1, trackedItems);
                    trackedItems = 0;

                    //Create another instance of the type NOT being tracked
                    //and ensure still only one tracked instance.
                    using (var t3 = new TestDisposable())
                    {
                        DisposableTracker.EnumerateTrackedInstances((td) => trackedItems++);
                        Assert.AreEqual(1, trackedItems);
                    }
                }
        }
Exemple #2
0
        public void TracksOnlyRegisteredTypes()
        {
            DisposableTracker.RegisterTrackedType(typeof(TestDisposable));
            using (var t = new TestDisposable())
                using (var t2 = new ReferenceCounted())
                {
                    int trackedItems = 0;
                    DisposableTracker.EnumerateTrackedInstances((td) => trackedItems++);

                    Assert.AreEqual(1, trackedItems);
                }
        }
Exemple #3
0
 public void RegisterTrackedTypeThrowsOnNull()
 {
     DisposableTracker.RegisterTrackedType(null);
 }