Exemple #1
0
        public void PoolingGeneralTypesInfoGenerationTest()
        {
            PoolManager poolManager = new PoolManager();

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

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

            Assert.That(poolManager.PoolContents.Count == 0);
            Assert.That(poolManager.TypesSupportData.Count == 1);
            Assert.That(poolManager.TypesSupportData.First().Key == poolSupportedObjectWithEvents.GetType());

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

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

            poolSupportedObjectWithProperties.DisableAndSendToPool();
            poolSupportedObjectWithEvents.DisableAndSendToPool();

            Assert.That(poolManager.PoolContents.Count != 0);
            Assert.That(poolManager.TypesSupportData.Count == 2);
        }
Exemple #2
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);
        }
Exemple #3
0
        public void EventsCleanupTest()
        {
            PoolManager poolManager = new PoolManager();

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

            //Assert.That(poolSupportedObjectWithEvents.IsAtLeastOneEventInvoked);

            poolSupportedObjectWithEvents.Init();
            poolSupportedObjectWithEvents.Event1 += ExampleInvokableMethodOutside;

            if (!poolSupportedObjectWithEvents.IsAtLeastOneEventInvoked())
            {
                Assert.Fail("Problems with events invokation inside of pool supported object");
            }

            poolSupportedObjectWithEvents.DisableAndSendToPool();

            Assert.That(!poolSupportedObjectWithEvents.IsAtLeastOneEventInvoked());
        }