public void AnotherObtainingOfSameObject_CreationTimestampIsNotModified()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseSameObjectPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);
            _pool.TryObtain(_key, out _outPoolObject, null);
            var previous = _pool.ObjectToLifetimeData[_outPoolObject].CreationTimeStamp;

            Thread.Sleep(5);
            _pool.TryObtain(_key, out _outPoolObject, null);

            var current = _pool.ObjectToLifetimeData[_outPoolObject].CreationTimeStamp;
            Assert.That(previous, Is.EqualTo(current).Within(_timeToleranceInMills).Milliseconds);
        }
        public void AnotherObtainingOfSameObject_RememberedObjectKeyIsPreserved()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseSameObjectPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);
            _pool.TryObtain(_key, out _outPoolObject, null);
            var previous = _pool.ObjectToLifetimeData[_outPoolObject].Key;

            _pool.TryObtain(_key, out _outPoolObject, null);

            var current = _pool.ObjectToLifetimeData[_outPoolObject].Key;
            Assert.That(previous, Is.EqualTo(current));
        }
        public void OnlyRevivalTimespanIsSpecified_TimestampsAreNotRememberedOnObtain()
        {
            _settings.MaxObjectIdleTimeSpanInSeconds = null;
            _settings.MaxObjectLifetimeInSeconds = null;
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseSuccessfulPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);

            _pool.TryObtain(_key, out _outPoolObject, null);

            Assert.That(_pool.ObjectToLifetimeData.Count, Is.EqualTo(0));
        }
        public void ObtainWasCalled_ProvidedObjectIsReturned()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseSuccessfulPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);

            var getStatus = _pool.TryObtain(_key, out _outPoolObject, null);

            Assert.That(getStatus, Is.True);
            Assert.That(_outPoolObject.Value, Is.EqualTo(_key.Identifier + " 1"));
        }
        public void ObtainWasCalled_BasePoolIsCalled()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseSuccessfulPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);
            Func<TestKey, TestResource> createDelegate = key => new TestResource(string.Empty);

            _pool.TryObtain(_key, out _outPoolObject, createDelegate);

            _baseSuccessfulPoolMock.Verify(x => x.TryObtain(_key, out _outPoolObject, createDelegate), Times.Once);
        }
        public void BasePoolThrewOnObtain_ItIsRethrownAsIs()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseThrowingPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);

            Assert.Throws<ObjectCreationFailedException<TestKey,TestResource>>(
                () => _pool.TryObtain(_key, out _outPoolObject, null));
        }
        public void BasePoolReturnedFalse_PoolIsNotBrokenAndJustReturnsFalse()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseNoObjectPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);

            var getStatus = _pool.TryObtain(_key, out _outPoolObject, null);

            Assert.That(getStatus, Is.False);
            Assert.That(_outPoolObject, Is.Null);
        }
        public void BasePoolProvidesObject_ObjectLifetimeDataAppears()
        {
            _pool = new PWObjectStateMonitoringWrapper<TestKey, TestResource>(_settings, _baseSuccessfulPoolMock.Object, _successfulObjectActionsMock.Object, _objectUtilizerMock.Object);

            _pool.TryObtain(_key, out _outPoolObject, null);

            var lifetimeData = _pool.ObjectToLifetimeData[_outPoolObject];
            Assert.That(lifetimeData.Key, Is.EqualTo(_key));
            Assert.That(lifetimeData.CreationTimeStamp, Is.EqualTo(DateTime.Now).Within(_timeToleranceInMills).Milliseconds);
            Assert.That(lifetimeData.LastUsageTimeStamp, Is.EqualTo(DateTime.Now).Within(_timeToleranceInMills).Milliseconds);
        }