public void SupportsRecursion__WriteLockIsHeld__AnotherLockCanBeAcquired()
        {
            var l = new ReaderWriterLockSlimEx(LockRecursionPolicy.SupportsRecursion);

            IReadLockAcquisition r;
            IUpgradeableReadLockAcquisition ur;
            IWriteLockAcquisition w;

            var a1 = l.AcquireReadLock();
            var a2 = l.TryAcquireReadLock(TEST_DefaultTimeout, out r);
            var a3 = l.TryAcquireUpgradeableReadLock(TEST_DefaultTimeout, out ur);
            var a4 = l.TryAcquireWriteLock(TEST_DefaultTimeout, out w);

            Assert.IsTrue(a2);
            Assert.IsFalse(a3);
            Assert.IsFalse(a4);
        }
        public void ReadLockIsHeld__AnotherThreadDoesNotBlockOnUpgradeableReadLockAcquisition()
        {
            var l = new ReaderWriterLockSlimEx();

            using (l.AcquireReadLock())
            {
                Task.Factory.StartNew(() =>
                {
                    var acquisition = (IUpgradeableReadLockAcquisition)null;

                    if (!l.TryAcquireUpgradeableReadLock(TEST_DefaultTimeout, out acquisition))
                    {
                        // should be able to acquire
                        Assert.Fail();
                    }
                }).Wait();
            }
        }
        public void UpgradeableReadLockIsHeld__AnotherThreadDoesNotBlockOnUpgradeableReadLockAcquisition()
        {
            // NOTE:    this is how Reader Writer Lock Slim works
            //          only one thread can own Upgradeable Read Lock at the time

            var l = new ReaderWriterLockSlimEx();

            using (l.AcquireUpgradeableReadLock())
            {
                Task.Factory.StartNew(() =>
                {
                    var acquisition = (IUpgradeableReadLockAcquisition)null;

                    if (l.TryAcquireUpgradeableReadLock(TEST_DefaultTimeout, out acquisition))
                    {
                        Assert.Fail();
                    }

                }).Wait();
            }
        }
        public void ReadLockIsHeld__CannotAcquireUpgradeableReadLock()
        {
            var l = new ReaderWriterLockSlimEx();

            using (var rl = l.AcquireReadLock())
            {
                var acquisition = (IUpgradeableReadLockAcquisition)null;

                if (l.TryAcquireUpgradeableReadLock(TEST_DefaultTimeout, out acquisition))
                {
                    // should not get here
                    Assert.Fail();
                }
            }
        }