// private methods
 private IConnection AcquireConnection(ExclusiveConnectionPool subject, bool async)
 {
     if (async)
     {
         return(subject
                .AcquireConnectionAsync(CancellationToken.None)
                .GetAwaiter()
                .GetResult());
     }
     else
     {
         return(subject.AcquireConnection(CancellationToken.None));
     }
 }
        public void AcquireConnection_should_throw_an_InvalidOperationException_if_not_initialized(
            [Values(false, true)]
            bool async)
        {
            Action act;

            if (async)
            {
                act = () => _subject.AcquireConnectionAsync(CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                act = () => _subject.AcquireConnection(CancellationToken.None);
            }

            act.ShouldThrow <InvalidOperationException>();
        }
        public void AcquireConnection_should_throw_an_InvalidOperationException_if_not_initialized(
            [Values(false, true)]
            bool async)
        {
            _capturedEvents.Clear();
            Action act;

            if (async)
            {
                act = () => _subject.AcquireConnectionAsync(CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                act = () => _subject.AcquireConnection(CancellationToken.None);
            }

            act.ShouldThrow <InvalidOperationException>();
            _capturedEvents.Next().Should().BeOfType <ConnectionPoolCheckingOutConnectionEvent>();
            var connectionPoolCheckingOutConnectionFailedEvent = _capturedEvents.Next();
            var e = connectionPoolCheckingOutConnectionFailedEvent.Should().BeOfType <ConnectionPoolCheckingOutConnectionFailedEvent>().Subject;

            e.Reason.Should().Be(ConnectionCheckOutFailedReason.ConnectionError);
            _capturedEvents.Any().Should().BeFalse();
        }
Exemple #4
0
        public void AcquireConnectionAsync_should_throw_an_InvalidOperationException_if_not_initialized()
        {
            Action act = () => _subject.AcquireConnectionAsync(CancellationToken.None).Wait();

            act.ShouldThrow <InvalidOperationException>();
        }