Exemple #1
0
        public void PoolAllAndRelease()
        {
            //create pool
            var pool = new PoolTest();

            //store all pooled objects
            var allPooledObjects = new List <PoolableObjectTest>();

            //pool all the start size
            for (var i = 0; i < pool.StartSize; i++)
            {
                var obj = pool.Get();
                allPooledObjects.Add(obj);
            }

            //assert the free objects list after pool
            Assert.True(pool.SizeFreeObjects == 0);

            //assert the busy objects list after pool
            Assert.True(pool.SizeBusyObjects == PoolTest.Size);

            foreach (var obj in allPooledObjects)
            {
                pool.Release(obj);
            }

            //assert the free objects list after pool
            Assert.True(pool.SizeFreeObjects == PoolTest.Size);

            //assert the busy objects list after pool
            Assert.True(pool.SizeBusyObjects == 0);
        }
Exemple #2
0
        public void ExceptionThrowsReleaseNullObject()
        {
            var pool = new PoolTest();

            void releaseNull() => pool.Release(null);

            Assert.Throws <GenericPooler <PoolableObjectTest> .GenericPoolerArgumentException>(releaseNull);
        }
Exemple #3
0
        public void ReleaseObjects()
        {
            //create new pool
            var pool = new PoolTest();

            //pool 1 object
            var obj = pool.Get();

            //release pooled object
            pool.Release(obj);

            //assert the free objects list after pool
            Assert.True(pool.SizeFreeObjects == PoolTest.Size);

            //assert the busy objects list after pool
            Assert.True(pool.SizeBusyObjects == 0);
        }