void TestPrimitiveObjectPoolsDispose() { PrimitiveObjectPool <TestObjectPoolItem> primPool = new PrimitiveObjectPool <TestObjectPoolItem>(1); ResizablePrimitiveObjectPool <TestObjectPoolItem> resizePool = new ResizablePrimitiveObjectPool <TestObjectPoolItem>(1); BlockingPrimitiveObjectPool <TestObjectPoolItem> blockPool = new BlockingPrimitiveObjectPool <TestObjectPoolItem>(1); primPool.Dispose(); resizePool.Dispose(); blockPool.Dispose(); Assert.Throws <ObjectDisposedException>(() => primPool.InUse); Assert.Throws <ObjectDisposedException>(() => primPool.PoolCount); Assert.Throws <ObjectDisposedException>(() => primPool.Size); Assert.Throws <ObjectDisposedException>(() => primPool.TryObtain(out var item)); Assert.Throws <ObjectDisposedException>(() => primPool.TryRelease(new TestObjectPoolItem())); Assert.Throws <ObjectDisposedException>(() => primPool.Obtain()); Assert.Throws <ObjectDisposedException>(() => primPool.Release(new TestObjectPoolItem())); Assert.Throws <ObjectDisposedException>(() => resizePool.InUse); Assert.Throws <ObjectDisposedException>(() => resizePool.PoolCount); Assert.Throws <ObjectDisposedException>(() => resizePool.Size); Assert.Throws <ObjectDisposedException>(() => resizePool.TryObtain(out var item)); Assert.Throws <ObjectDisposedException>(() => resizePool.TryRelease(new TestObjectPoolItem())); Assert.Throws <ObjectDisposedException>(() => resizePool.Obtain()); Assert.Throws <ObjectDisposedException>(() => resizePool.Release(new TestObjectPoolItem())); Assert.Throws <ObjectDisposedException>(() => blockPool.InUse); Assert.Throws <ObjectDisposedException>(() => blockPool.PoolCount); Assert.Throws <ObjectDisposedException>(() => blockPool.Size); Assert.Throws <ObjectDisposedException>(() => blockPool.TryObtain(out var item)); Assert.Throws <ObjectDisposedException>(() => blockPool.TryRelease(new TestObjectPoolItem())); Assert.Throws <ObjectDisposedException>(() => blockPool.Obtain()); Assert.Throws <ObjectDisposedException>(() => blockPool.Release(new TestObjectPoolItem())); }
void TestPrimitiveObjectPoolObtainRelease() { PrimitiveObjectPool <TestObjectPoolItem> primPool = new PrimitiveObjectPool <TestObjectPoolItem>(3); Assert.Equal(3, primPool.Size); Assert.Equal(0, primPool.InUse); Assert.Equal(3, primPool.PoolCount); TestObjectPoolItem test = new TestObjectPoolItem(); Assert.False(primPool.TryRelease(test)); Assert.Equal(3, primPool.Size); Assert.Equal(0, primPool.InUse); Assert.Equal(3, primPool.PoolCount); Assert.Throws <InvalidOperationException>(() => primPool.Release(test)); Assert.Equal(3, primPool.Size); Assert.Equal(0, primPool.InUse); Assert.Equal(3, primPool.PoolCount); TestObjectPoolItem test1; TestObjectPoolItem test2; TestObjectPoolItem test3; TestObjectPoolItem test4; Assert.True(primPool.TryObtain(out test1)); Assert.NotNull(test1); Assert.Equal(3, primPool.Size); Assert.Equal(1, primPool.InUse); Assert.Equal(2, primPool.PoolCount); test2 = primPool.Obtain(); Assert.NotNull(test2); Assert.Equal(3, primPool.Size); Assert.Equal(2, primPool.InUse); Assert.Equal(1, primPool.PoolCount); test3 = primPool.Obtain(); Assert.NotNull(test3); Assert.Equal(3, primPool.Size); Assert.Equal(3, primPool.InUse); Assert.Equal(0, primPool.PoolCount); Assert.False(primPool.TryObtain(out test4)); Assert.Null(test4); Assert.Equal(3, primPool.Size); Assert.Equal(3, primPool.InUse); Assert.Equal(0, primPool.PoolCount); Assert.Throws <InvalidOperationException>(() => test4 = primPool.Obtain()); Assert.Null(test4); Assert.Equal(3, primPool.Size); Assert.Equal(3, primPool.InUse); Assert.Equal(0, primPool.PoolCount); Assert.True(primPool.TryRelease(test1)); Assert.Equal(3, primPool.Size); Assert.Equal(2, primPool.InUse); Assert.Equal(1, primPool.PoolCount); primPool.Release(test1); Assert.Equal(3, primPool.Size); Assert.Equal(1, primPool.InUse); Assert.Equal(2, primPool.PoolCount); primPool.Release(test1); Assert.Equal(3, primPool.Size); Assert.Equal(0, primPool.InUse); Assert.Equal(3, primPool.PoolCount); }