public void ShouldHandleClearAndThenPoolCanBeUsedAgain()
        {
            var pool = new ParameterizedObjectPool <int, MyPooledObject>();

            using (var obj = pool.GetObject(1))
            {
            }

            pool.Clear();

            using (var obj = pool.GetObject(1))
            {
            }

            Assert.That(1, Is.EqualTo(pool.KeysInPoolCount));
        }
 public ParallelLoopResult Parameterized() => Parallel.For(0, Count, _ =>
 {
     string str;
     using (var x = _paramObjectPool.GetObject(21))
     {
         str = x.Value;
     }
 });
        public string Parameterized()
        {
            string str;

            using (var x = _paramObjectPool.GetObject(21))
            {
                str = x.Value;
            }
            return(str);
        }
        public void ShouldHandleClearAfterSomeUsage()
        {
            var pool = new ParameterizedObjectPool <int, MyPooledObject>();

            using (var obj = pool.GetObject(1))
            {
            }

            pool.Clear();

            Assert.That(0, Is.EqualTo(pool.KeysInPoolCount));
        }
        public async Task ShouldSimplyWork(int maxSize)
        {
            const int keyCount    = 4;
            var       pool        = new ParameterizedObjectPool <int, MyPooledObject>(maxSize);
            var       objectCount = maxSize * keyCount;
            var       objects     = new MyPooledObject[objectCount];

            Parallel.For(0, objectCount, i =>
            {
                objects[i] = pool.GetObject(i % keyCount);
            });
            Parallel.For(0, objectCount, i =>
            {
                objects[i].Dispose();
            });

            await Task.Delay(1000);

            Assert.AreEqual(keyCount, pool.KeysInPoolCount);
        }
        public async Task ShouldSimplyWork(int maxSize)
        {
            const int keyCount = 4;
            var pool = new ParameterizedObjectPool<int, MyPooledObject>(0, maxSize);
            var objectCount = maxSize * keyCount;
            var objects = new MyPooledObject[objectCount];
            Parallel.For(0, objectCount, i =>
            {
                objects[i] = pool.GetObject(i % keyCount);
            });
            Parallel.For(0, objectCount, i =>
            {
                objects[i].Dispose();
            });
#if !NET40
            await Task.Delay(1000);
#else
            await TaskEx.Delay(1000);
#endif
            Assert.AreEqual(keyCount, pool.KeysInPoolCount);
        }
        public void ShouldHandleClearAndThenPoolCanBeUsedAgain()
        {
            var pool = new ParameterizedObjectPool<int, MyPooledObject>();

            using (var obj = pool.GetObject(1))
            {
            }

            pool.Clear();

            using (var obj = pool.GetObject(1))
            {
            }

            Assert.That(1, Is.EqualTo(pool.KeysInPoolCount));
        }
        public void ShouldHandleClearAfterSomeUsage()
        {
            var pool = new ParameterizedObjectPool<int, MyPooledObject>();

            using (var obj = pool.GetObject(1))
            {
            }

            pool.Clear();

            Assert.That(0, Is.EqualTo(pool.KeysInPoolCount));
        }