/// <summary> /// Called when connection is established and communication is available. /// </summary> /// <param name="socket">The socket.</param> /// <returns></returns> public virtual async Task OnConnected(WebSocket socket) { if (socket == null) { throw new NullReferenceException("socket is null"); } ConnectionId = WebSocketManager.AddConnection(new Connection { Socket = socket }); await SendMessageToClientAsync(socket, JsonConvert.SerializeObject(new { socketId = ConnectionId, action = WebSocketRequestType.WebSocketInit }, Formatting.None)); }
public void AddSocketWithCustomIdToListTest() { var res = manager.AddConnection(connection.Object, testStr); var testList = new ConcurrentDictionary <string, Connection>(); testList.TryAdd(testStr, connection.Object); Assert.Equal(res, testStr); Assert.Contains(testStr, manager.Connections.Keys); Assert.Contains(connection.Object, manager.Connections.Values); Assert.Equal(testList, manager.Connections); }