public void SwitchConnection_Execute() { // Verify the Execute command. var handlerDone = false; var gotCommand = false; var connectHandler = new EventHandler <SwitchInboundConnectionArgs>( (s, a) => { a.StartConnectionThread = false; Helper.EnqueueAction(() => { SwitchConnection serverConnection = a.Connection; SwitchPacket packet; AuthHandshake(serverConnection, false); packet = serverConnection.ReceivePacket(); gotCommand = packet.PacketType == SwitchPacketType.Command && packet.CommandText == "api status" && packet.Headers.Count == 0; serverConnection.SendReply(null); serverConnection.SendResponse("foobar"); serverConnection.Close(); handlerDone = true; }); }); SwitchConnection.InboundConnection += connectHandler; try { SwitchConnection.StartListener(binding, 10); SwitchConnection connection = new SwitchConnection(binding, SwitchConnection.DefaultPassword); CommandDisposition disposition; connection.Connect(); disposition = connection.Execute("status"); Assert.IsTrue(disposition.Success); Assert.AreEqual("foobar", disposition.ResponseText); Helper.WaitFor(() => handlerDone, TimeSpan.FromMilliseconds(5000)); Assert.IsTrue(gotCommand); } finally { SwitchConnection.InboundConnection -= connectHandler; SwitchConnection.StopListener(); } }