コード例 #1
0
        public void AllObjectsAreNotAvailable_ObtainWithCreateDelegateReturnsNewlyCreatedObject()
        {
            _settings.MarkObtainedObjectAsNotAvailable = true;
            AddAvailableObject("1");
            _poolItem.TryObtain(out _anotherOutPoolObject, null);
            var createDelegateWithCounter = new CreateDelegateWithCounter(3);

            var getResult = _poolItem.TryObtain(out _outPoolObject, createDelegateWithCounter.Delegate);

            Assert.That(getResult, Is.True);
            Assert.That(_outPoolObject.Value, Is.EqualTo("3"));
            Assert.That(createDelegateWithCounter.NumberOfCallings, Is.EqualTo(1));
        }
コード例 #2
0
        public void AllAvailableObjectsBecameInvalid_PoolItemForgotsThemAndReturnsAnotherObject()
        {
            AddAvailableObject("1" + Mocks.ObjectActions.SubstringOfInvalidObject);
            AddAvailableObject("2" + Mocks.ObjectActions.SubstringOfInvalidObject);
            var createDelegateWithCounter = new CreateDelegateWithCounter(5);

            var getStatus = _poolItem.TryObtain(out _outPoolObject, createDelegateWithCounter.Delegate);

            Assert.That(getStatus, Is.True);
            Assert.That(_outPoolObject.Value, Is.EqualTo("5"));
            Assert.That(createDelegateWithCounter.NumberOfCallings, Is.EqualTo(1));
            Assert.That(_poolItem.AllObjectsCount, Is.EqualTo(1));
        }
コード例 #3
0
        public void PoolItemIsEmpty_ObtainWithCreateDelegateReturnsNewlyCreatedObject()
        {
            var createDelegateWithCounter = new CreateDelegateWithCounter(3);

            var getResult = _poolItem.TryObtain(out _outPoolObject, createDelegateWithCounter.Delegate);

            Assert.That(getResult, Is.True);
            Assert.That(_outPoolObject.Value, Is.EqualTo("3"));
            Assert.That(createDelegateWithCounter.NumberOfCallings, Is.EqualTo(1));
        }
コード例 #4
0
        public void MarkingIsOn_ReferenceToCreatedObjectIsPreserved()
        {
            _settings.MarkObtainedObjectAsNotAvailable = true;
            var createDelegateWithCounter = new CreateDelegateWithCounter(1);

            _poolItem.TryObtain(out _outPoolObject, createDelegateWithCounter.Delegate);

            Assert.That(_poolItem.NotAvailableObjectsCount, Is.EqualTo(1));
        }