Ejemplo n.º 1
0
        public void DisposableExtensions_Unit_InvokeDispose_Optimal()
        {
            Object nonDisposableObject = new Object();
            DisposableBase disposableObject = new MockDisposableBase();
            IEnumerable<DisposableBase> disposableCollection = new List<DisposableBase>() {
                new MockDisposableBase(),
                new MockDisposableBase(),
                new MockDisposableBase()
            };
            IntPtr intPtr = new IntPtr(12345);
            try {
                using (MockReflectionDisposable disposable = new MockReflectionDisposable(nonDisposableObject, disposableObject, disposableCollection, intPtr)) {
                    DisposableExtensions.InvokeDispose(disposable);

                    Assert.IsNull(disposable.DisposableObject);
                    Assert.IsTrue(disposableObject.IsDisposed);
                    Assert.IsTrue(disposable.DisposableCollection.All(item => item.IsDisposed));
                    Assert.AreEqual(IntPtr.Zero, disposable.IntPtr);
                }

                using (MockReflectionDisposable disposable = new MockReflectionDisposable(null, null, null, IntPtr.Zero)) {
                    DisposableExtensions.InvokeDispose(disposable);
                }
            }
            finally {
                if (intPtr != IntPtr.Zero) {
                    intPtr = IntPtr.Zero;
                }
            }
        }
Ejemplo n.º 2
0
        public void DisposableBase_Integration_Serialization_IsDisposed()
        {
            DisposableBase original = new MockDisposableBase();
            original.Dispose();

            DisposableBase clone = original.SerializeBinary();
            Assert.AreEqual(true, clone.IsDisposed);
        }
Ejemplo n.º 3
0
        public void DisposableBase_Integration_Serialization_Optimal()
        {
            DisposableBaseTests.ReleaseManagedResourcesCalled = false;
            DisposableBaseTests.ReleaseUnmanagedResourcesCalled = false;
            DisposableBase original = new MockDisposableBase(DisposableBaseTests.ReleaseManagedResources, DisposableBaseTests.ReleaseUnmanagedResources);

            DisposableBase clone = original.SerializeBinary();
            Assert.AreEqual(original.IsDisposed, clone.IsDisposed);
            Assert.AreEqual(false, DisposableBaseTests.ReleaseManagedResourcesCalled);
            Assert.AreEqual(false, DisposableBaseTests.ReleaseUnmanagedResourcesCalled);

            clone.Dispose();
            Assert.AreEqual(true, DisposableBaseTests.ReleaseManagedResourcesCalled);
            Assert.AreEqual(true, DisposableBaseTests.ReleaseUnmanagedResourcesCalled);
        }
Ejemplo n.º 4
0
 public void DisposableBase_Unit_ThrowIfDisposed_NotDisposed()
 {
     MockDisposableBase target = new MockDisposableBase();
     target.TestMethod();
 }
Ejemplo n.º 5
0
        public void DisposableBase_Unit_Dispose_Optimal()
        {
            DisposableBaseTests.ReleaseManagedResourcesCalled = false;
            DisposableBaseTests.ReleaseUnmanagedResourcesCalled = false;
            DisposableBase target = new MockDisposableBase(DisposableBaseTests.ReleaseManagedResources, DisposableBaseTests.ReleaseUnmanagedResources);
            Assert.AreEqual(false, target.IsDisposed);
            Assert.AreEqual(false, DisposableBaseTests.ReleaseManagedResourcesCalled);
            Assert.AreEqual(false, DisposableBaseTests.ReleaseUnmanagedResourcesCalled);

            target.Dispose();
            Assert.AreEqual(true, target.IsDisposed);
            Assert.AreEqual(true, DisposableBaseTests.ReleaseManagedResourcesCalled);
            Assert.AreEqual(true, DisposableBaseTests.ReleaseUnmanagedResourcesCalled);
        }
Ejemplo n.º 6
0
 public void DisposableBase_Unit_Dispose_CallTwice()
 {
     DisposableBase target = new MockDisposableBase();
     target.Dispose();
     target.Dispose();
 }