/// <summary>
        /// Creates and starts a client.
        /// </summary>
        /// <param name="ipAdress">The ip adress.</param>
        /// <param name="port">The port.</param>
        /// <param name="connectRetryWaitMs">The connect retry wait ms.</param>
        /// <param name="id">The identifier. This identifier has to be matched be the listener this client will connect to. The listener will be determined, when the first msg is send.</param>
        /// <returns></returns>
        protected int CreateAndStartClient(IPAddress ipAdress, int port, int connectRetryWaitMs, int id, IMessageValidator messageValidator)
        {
            var client = new ConnectionBuffer <TMessage>
            {
                Id         = id,
                Connection = _binaryConnectionFactory.Create(CreateClientConfig(ipAdress, port, connectRetryWaitMs), messageValidator)
            };

            client.Connection.Received +=
                (sender, message) => client.Received.Add((TMessage)message);
            client.Connection.NotifyConnectionState += (sender, message) => client.LastStateChangeEvents.Add(message);

            var clientIdx = _clients.Count;

            _clients.Add(client);
            _overallClients.Add(client);

            Console.WriteLine("CreateAndStartClient Added Client idx: {0}.", clientIdx);

            // Client should be disconnected
            Assert.AreEqual(_clients[clientIdx].Connection.CurrentState, BinaryConnectionState.Disconnected,
                            $"Client is not in the state '{BinaryConnectionState.Disconnected:G}'. CurrentState: {_clients[clientIdx].Connection.CurrentState:G}");

            _clients[clientIdx].Connection.Start();

            // In some tests the client shall be connected at this point and in some tests it shall not be connected,
            // so check the connection-state somewhere else...

            return(clientIdx);
        }
        /// <summary>
        /// Creates and starts a listener on the server. There has to be one listener for each clients that shall connect.
        /// </summary>
        /// <param name="ipAdress">The ip adress.</param>
        /// <param name="port">The port.</param>
        /// <param name="id">The identifier. This identifier has to be matched be the client that connects to this listener. The listener will be determined, when the first message is received</param>
        /// <param name="messageValidator">The message validator to be used</param>
        protected ConnectionBuffer <TMessage> CreateAndStartServer(IPAddress ipAdress, int port, int id, IMessageValidator messageValidator)
        {
            var server = new ConnectionBuffer <TMessage>
            {
                Id         = id,
                Connection = _binaryConnectionFactory.Create(CreateServerConfig(ipAdress, port), messageValidator)
            };

            server.Connection.Received += (sender, message) => server.Received.Add((TMessage)message);
            server.Connection.NotifyConnectionState += (sender, message) => server.LastStateChangeEvents.Add(message);

            // Server should be disconnected
            Assert.AreEqual(server.Connection.CurrentState, BinaryConnectionState.Disconnected,
                            $"server is not in the state '{BinaryConnectionState.Disconnected:G}'. CurrentState: {server.Connection.CurrentState:G}");

            server.Connection.Start();

            // Server should be listening
            Assert.AreEqual(BinaryConnectionState.AttemptingConnection, server.Connection.CurrentState,
                            $"server is not in the state '{BinaryConnectionState.AttemptingConnection:G}'. CurrentState: {server.Connection.CurrentState:G}");

            _serverConnections.Add(server);

            return(server);
        }