Esempio n. 1
0
        public void PoolingGeneralObjectStorageTest()
        {
            PoolManager poolManager = new PoolManager();

            Assert.That(poolManager.PoolContents.Count == 0);

            PoolSupportedObjectWithEvents poolSupportedObjectWithEvents =
                poolManager.GetObject <PoolSupportedObjectWithEvents>(typeof(PoolSupportedObjectWithEvents));

            Assert.That(poolManager.PoolContents.Count == 0);

            PoolSupportedObjectWithFields poolSupportedObjectWithFields =
                poolManager.GetObject <PoolSupportedObjectWithFields>(typeof(PoolSupportedObjectWithFields));

            Assert.That(poolManager.PoolContents.Count == 0);

            PoolSupportedObjectWithProperties poolSupportedObjectWithProperties =
                poolManager.GetObject <PoolSupportedObjectWithProperties>(typeof(PoolSupportedObjectWithProperties));

            Assert.That(poolManager.PoolContents.Count == 0);

            poolSupportedObjectWithEvents.DisableAndSendToPool();

            Assert.That(poolManager.PoolContents.Count == 1);
            Assert.That(poolManager.PoolContents.First().Value.Count == 1);

            PoolSupportedObjectWithEvents poolSupportedObjectWithEventsDublicated =
                poolManager.GetObject <PoolSupportedObjectWithEvents>(typeof(PoolSupportedObjectWithEvents));

            Assert.That(poolManager.PoolContents.First().Value.Count == 0);
            Assert.AreEqual(poolSupportedObjectWithEvents, poolSupportedObjectWithEventsDublicated);

            poolSupportedObjectWithFields.DisableAndSendToPool();
            poolSupportedObjectWithProperties.DisableAndSendToPool();

            Assert.That(poolManager.PoolContents.Count == 3);

            int objectsOperationsCount = 100;

            PoolSupportedObject[] supportedObjects = new PoolSupportedObject[objectsOperationsCount];

            for (int i = 0; i < objectsOperationsCount; i++)
            {
                supportedObjects[i] = poolManager.GetObject <PoolSupportedObject>(typeof(PoolSupportedObjectWithEvents));
                supportedObjects[i].DisableAndSendToPool();
            }

            Assert.That(poolManager.PoolContents.First().Value.Count == 1);
        }
Esempio n. 2
0
        public void FieldsCleanupTest()
        {
            PoolManager poolManager = new PoolManager();

            PoolSupportedObjectWithFields poolSupportedObjectWithFields =
                poolManager.GetObject <PoolSupportedObjectWithFields>(typeof(PoolSupportedObjectWithFields));

            poolSupportedObjectWithFields.Init();

            Assert.That(!poolSupportedObjectWithFields.IsEverythingDefault());

            poolSupportedObjectWithFields.DisableAndSendToPool();

            Assert.That(poolSupportedObjectWithFields.IsEverythingDefault());
        }