public async Task CloseRepository() { if (WebSocketConnection != null) { WebSocketConnection.OnClose -= WebSocketConnection_OnClose; await WebSocketConnection.DisconnectAsync(); WebSocketConnection = null; } }
public async Task ConnectDisconnect_ValidStatusAndInvokesConnectionEvents() { using ServerWebSocketConnection server = WebSocketServer.CreateServer(TEST_CONNECTION_PORT); bool connected = false; bool serverSideDisconnected = false, clientSideDisconnected = false; server.OnClientConnected += (o, a) => connected = true; server.OnClose += (o, a) => serverSideDisconnected = true; _ = Task.Run(server.RunServerLoop); using WebSocketConnection client = await WebSocketClient.ConnectAsync(TEST_CONNECTION_URI); client.OnClose += (o, a) => clientSideDisconnected = true; Assert.IsTrue(connected); Assert.IsFalse(serverSideDisconnected); Assert.IsFalse(clientSideDisconnected); await client.DisconnectAsync(); Assert.IsTrue(serverSideDisconnected); Assert.IsTrue(clientSideDisconnected); }
public void Disconnect() { socketConnection.DisconnectAsync(); }