public void SwitchConnection_SetLogLevel() { // Verify the SetLogLevel 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); // First command should be: log 5 (notify) packet = serverConnection.ReceivePacket(); gotCommand = packet.PacketType == SwitchPacketType.Command && packet.CommandText == "log 5" && packet.Headers.Count == 0; serverConnection.SendReply(null); serverConnection.SendResponse("log level set"); // Second command should be: log 2 (critical) packet = serverConnection.ReceivePacket(); gotCommand = packet.PacketType == SwitchPacketType.Command && packet.CommandText == "log 2" && packet.Headers.Count == 0; serverConnection.SendReply(null); serverConnection.SendResponse("log level set"); // Third command should be: nolog packet = serverConnection.ReceivePacket(); gotCommand = packet.PacketType == SwitchPacketType.Command && packet.CommandText == "nolog" && packet.Headers.Count == 0; serverConnection.SendReply(null); serverConnection.SendResponse("logging disabled"); serverConnection.Close(); handlerDone = true; }); }); SwitchConnection.InboundConnection += connectHandler; try { SwitchConnection.StartListener(binding, 10); SwitchConnection connection = new SwitchConnection(binding, SwitchConnection.DefaultPassword); CommandDisposition disposition; connection.Connect(); Assert.AreEqual(SwitchLogLevel.None, connection.LogLevel); disposition = connection.SetLogLevel(SwitchLogLevel.Notice); Assert.IsTrue(disposition.Success); Assert.AreEqual("log level set", disposition.ResponseText); Assert.AreEqual(SwitchLogLevel.Notice, connection.LogLevel); disposition = connection.SetLogLevel(SwitchLogLevel.Critical); Assert.IsTrue(disposition.Success); Assert.AreEqual("log level set", disposition.ResponseText); Assert.AreEqual(SwitchLogLevel.Critical, connection.LogLevel); disposition = connection.SetLogLevel(SwitchLogLevel.None); Assert.IsTrue(disposition.Success); Assert.AreEqual("logging disabled", disposition.ResponseText); Assert.AreEqual(SwitchLogLevel.None, connection.LogLevel); Helper.WaitFor(() => handlerDone, TimeSpan.FromMilliseconds(5000)); Assert.IsTrue(gotCommand); } finally { SwitchConnection.InboundConnection -= connectHandler; SwitchConnection.StopListener(); } }