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)); }
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)); }
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)); }
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)); }