public async Task GivenAMessageToAllWhenExecutingHandleThanReturnTheFormattedMessage() { var nickname = "foo"; var message = "message"; var expected = ServerMessageConstants.GetMessage(ServerMessageConstants.GENERAL_MESSAGE, nickname, message); Mock <WebSocket> originSocketMock = new Mock <WebSocket>(); Mock <ISocketHandler> socketHandlerMock = new Mock <ISocketHandler>(); var chatMessageHandler = new ChatMessageHandler(socketHandlerMock.Object); var taskResult = await chatMessageHandler.Handle(originSocketMock.Object, nickname, message); Assert.Equal(taskResult, expected); }
/// <summary> /// Recieves the request /// </summary> /// <param name="socket"></param> /// <param name="result"></param> /// <param name="buffer"></param> /// <returns></returns> public async Task RecieveRequest(WebSocket socket, WebSocketReceiveResult result, byte[] buffer) { var nickname = _connectionManager.GetNickNameBySocket(socket); var rawMessage = buffer.GetBufferedMessage(result.Count); if (string.IsNullOrWhiteSpace(nickname)) { await _chatRegistrationHandler.Handle(socket, nickname, rawMessage); } else if (rawMessage.StartsWith("/")) { await _chatCommandHandler.Handle(socket, nickname, rawMessage); } else { await _chatMessageHandler.Handle(socket, nickname, rawMessage); } }