public void Create()
 {
     using (var x = new FakeNativeObject((IntPtr)1, false)) {
         Assert.That(x.RetainCount, Is.EqualTo(1), "x.RetainCount");
     }
     using (var y = new FakeNativeObject((IntPtr)2, true)) {
         Assert.That(y.RetainCount, Is.EqualTo(0), "y.RetainCount");
     }
 }
        public void Dispose()
        {
            var x = new FakeNativeObject((IntPtr)1, false);

            Assert.That(x.RetainCount, Is.EqualTo(1), "1");
            x.Dispose();
            Assert.That(x.RetainCount, Is.EqualTo(0), "0");
            Assert.Throws <ObjectDisposedException> (() => x.GetCheckedHandle(), "Dispose");
            // Dispose should be safe to call multiple times
            x.Dispose();
        }
        public void Equals()
        {
            // overriden Equals with weird behavior to confirm it can't be anything else
            using (var x = new FakeNativeObject((IntPtr)42, true)) {
                Assert.False(x.Equals(x), "self");
                Assert.True(x.Equals(null), "null");
            }
#if NET
            // check that equality is based on handle only (and not System.Object.Equals)
            using (var n1 = new NativeObjectPoker((IntPtr)42))
                using (var n2 = new NativeObjectPoker((IntPtr)42))
                    Assert.True(n1.Equals(n2), "1");
#endif
        }
        public void GetHashCodeValue()
        {
            // check that overriding GetHashCode is fine
            using (var n = new FakeNativeObject((IntPtr)42, true)) {
                Assert.That(n.GetHashCode, Is.EqualTo(0), "GetHashCode");
            }
#if NET
            // check that only the handle is used to compute the hash code of the selector
            // which means DisposableObject base implementation (not System.Object) is used
            using (var n = new NativeObjectPoker((IntPtr)42)) {
                Assert.AreNotEqual(n.GetHashCode(), RuntimeHelpers.GetHashCode(n), "GetHashCode-old");
                Assert.AreEqual(n.GetHashCode(), n.Handle.GetHashCode(), "GetHashCode-net");
            }
#endif
        }