Exemplo n.º 1
0
        public void Dispose_CallsExplicitAndImplicitDisposal()
        {
            // Arrange
            var @explicit  = false;
            var @implicit  = false;
            var disposable = new FinalizeDisposableIndexedSet <string>(
                onExplicitDispose: () => @explicit = true,
                onImplicitDispose: () => @implicit = true);

            // Act
            disposable.Dispose();

            // Assert
            Assert.True(@explicit);
            Assert.True(@implicit);
        }
Exemplo n.º 2
0
        public void FinalizerTest()
        {
            // Arrange
            var @explicit = false;
            var @implicit = false;
            WeakReference <FinalizeDisposableIndexedSet <string> > weak = null;
            Action dispose = () =>
            {
                // This will go out of scope after dispose() is executed
                var disposable = new FinalizeDisposableIndexedSet <string>(
                    onExplicitDispose: () => @explicit = true,
                    onImplicitDispose: () => @implicit = true);
                weak = new WeakReference <FinalizeDisposableIndexedSet <string> >(disposable, true);
            };

            // Act
            dispose();
            GC.Collect(0, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            // Assert
            Assert.False(@explicit); // Not called through finalizer
            Assert.True(@implicit);
        }