public void Constructor_Should_CreateEmptyInstance()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            Assert.True(@lock.CanRead);
            Assert.Equal(0, @lock.ReaderCount);
        }
        public void IntegrationTest1()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            Assert.True(@lock.CanRead);
            Assert.Equal(0, @lock.ReaderCount);

            @lock.EnterRead();

            Assert.True(@lock.CanRead);
            Assert.Equal(1, @lock.ReaderCount);

            @lock.EnterRead();

            Assert.True(@lock.CanRead);
            Assert.Equal(2, @lock.ReaderCount);

            @lock.ExitRead();

            Assert.True(@lock.CanRead);
            Assert.Equal(1, @lock.ReaderCount);

            @lock.ExitRead();

            Assert.True(@lock.CanRead);
            Assert.Equal(0, @lock.ReaderCount);
        }
        public void CreateWriteSessionAsync_Should_Throw_ObjectDisposed_When_InstanceWasDisposed()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            @lock.Dispose();

            Assert.ThrowsAsync <ObjectDisposedException>(@lock.CreateWriteSessionAsync);
        }
        public void Dispose_Should_DisposeInstance()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            @lock.Dispose();

            AllMethods_Should_Throw_ObjectDisposedException(@lock);
        }
        public void DisableReadLockAsync_Should_Throw_ObjectDisposed_When_InstanceWasDisposed()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            @lock.Dispose();

            Assert.ThrowsAsync <ObjectDisposedException>(@lock.DisableReadLockAsync);
        }
        public void ExitWrite_Should_Throw_ObjectDisposed_When_InstanceWasDisposed()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            @lock.Dispose();

            Assert.Throws <ObjectDisposedException>(@lock.ExitWrite);
        }
        public void IntegrationTest2()
        {
            ConsumerProducerLock @lock = new ConsumerProducerLock();

            Assert.True(@lock.CanRead);
            Assert.Equal(0, @lock.ReaderCount);

            using (ReadSession readSession = @lock.CreateReadSession())
            {
                Assert.True(@lock.CanRead);
                Assert.Equal(1, @lock.ReaderCount);
            }

            Assert.True(@lock.CanRead);
            Assert.Equal(0, @lock.ReaderCount);
        }
 private void AllMethods_Should_Throw_ObjectDisposedException(ConsumerProducerLock @lock)
 {
     Assert.Throws <ObjectDisposedException>(@lock.CreateReadSession);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.CreateReadSessionAsync);
     Assert.Throws <ObjectDisposedException>(@lock.CreateWriteSession);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.CreateWriteSessionAsync);
     Assert.Throws <ObjectDisposedException>(@lock.EnterRead);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.EnterReadAsync);
     Assert.Throws <ObjectDisposedException>(@lock.ExitRead);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.ExitReadAsync);
     Assert.Throws <ObjectDisposedException>(@lock.EnterWrite);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.EnterWriteAsync);
     Assert.Throws <ObjectDisposedException>(@lock.ExitWrite);
     Assert.Throws <ObjectDisposedException>(@lock.EnableReadLock);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.EnableReadLockAsync);
     Assert.Throws <ObjectDisposedException>(@lock.DisableReadLock);
     Assert.ThrowsAsync <ObjectDisposedException>(@lock.DisableReadLockAsync);
 }