コード例 #1
0
        public void TestPooling()
        {
            PoolFactory <object> factory = new PoolFactory <object>(10);

            // We allocate 10 objects ahead because a valid pool factory implementation could
            // decide to only start returning reused objects after the pool is full to quickly
            // grow the pool at the beginning.
            object[] objects = new object[10];
            for (int index = 0; index < objects.Length; ++index)
            {
                objects[index] = factory.Take();
            }

            for (int index = objects.Length - 1; index >= 0; --index)
            {
                factory.Redeem(objects[index]);
            }

            for (int index = 0; index < objects.Length; ++index)
            {
                Assert.Contains(factory.Take(), objects);
            }
        }
コード例 #2
0
        public void TestViaGenericFactoryInterface()
        {
            IAbstractFactory <object> factory = new PoolFactory <object>(10);

            Assert.IsNotNull(factory.CreateInstance());
        }
コード例 #3
0
        public void TestExplicitConstructor()
        {
            PoolFactory <object> factory = new PoolFactory <object>(100);

            Assert.IsNotNull(factory); // Nonsense; prevents compiler warning
        }