private async Task ReceiveAsync()
        {
            _recvLock.Wait();

            try
            {
                if (_responsePipeline.HasNoPendingMessages)
                {
                    return;
                }

                await _client.ReceiveAsync(_responsePipeline).ConfigureAwait(false);

                _responsePipeline.AssertNoFailure();
            }
            finally
            {
                _recvLock.Release();
            }
        }
            public MockedConnection(AccessMode mode, List <Tuple <IRequestMessage, IResponseMessage> > messages,
                                    ServerInfo serverInfo = null)
            {
                foreach (var pair in messages)
                {
                    if (pair.Item1 != null)
                    {
                        _requestMessages.Add(pair.Item1);
                    }

                    if (pair.Item2 != null)
                    {
                        _responseMessages.Add(pair.Item2);
                    }
                }

                _mockConn.Setup(x => x.EnqueueAsync(It.IsAny <IRequestMessage>(), It.IsAny <IResponseHandler>(),
                                                    It.IsAny <IRequestMessage>(), It.IsAny <IResponseHandler>()))
                .Returns(Task.CompletedTask)
                .Callback <IRequestMessage, IResponseHandler, IRequestMessage, IResponseHandler>(
                    (msg1, handler1, msg2, handler2) =>
                {
                    msg1.ToString().Should().Be(_requestMessages[_requestCount].ToString());
                    _requestCount++;
                    _pipeline.Enqueue(msg1, handler1);

                    if (msg2 != null)
                    {
                        msg2.ToString().Should().Be(_requestMessages[_requestCount].ToString());
                        _requestCount++;
                        _pipeline.Enqueue(msg2, handler2);
                    }
                });
                _mockConn.Setup(x => x.ReceiveOneAsync())
                .Returns(() =>
                {
                    if (_responseCount < _responseMessages.Count)
                    {
                        _responseMessages[_responseCount].Dispatch(_pipeline);
                        _responseCount++;
                        _pipeline.AssertNoFailure();
                        return(Task.CompletedTask);
                    }
                    else
                    {
                        throw new InvalidOperationException("Not enough response message to provide");
                    }
                });

                _mockConn.Setup(x => x.IsOpen).Returns(() => _responseCount < _responseMessages.Count);
                _mockConn.Setup(x => x.Mode).Returns(mode);
                var protocol = BoltProtocolV3.BoltV3;

                if (serverInfo != null)
                {
                    if (ServerVersion.From(serverInfo.Version) >= ServerVersion.V4_0_0)
                    {
                        protocol = BoltProtocolV4.BoltV4;
                    }

                    _mockConn.Setup(x => x.Server).Returns(serverInfo);
                }
                else
                {
                    _mockConn.Setup(x => x.Server)
                    .Returns(new ServerInfo(new Uri("bolt://123:456"))
                    {
                        Version = "Neo4j/3.5.0"
                    });
                }

                _mockConn.Setup(x => x.BoltProtocol).Returns(protocol);
            }