public void ReadCallback(IAsyncResult ar) { StateObject state = (StateObject)ar.AsyncState; Socket = state.WorkSocket; ISocketMessage message = new JsonSocketMessage(); try { int bytesRead = Socket.EndReceive(ar); if (bytesRead > 0) { foreach (var msg in message.Deserialize(state.Buffer)) { switch (msg.MessageType) { case SocketMessageType.Method: MethodRecievedEvent?.Invoke(this, MethodSignatureDto.DeserializeMethodObject(msg.Message)); break; case SocketMessageType.Methods: break; case SocketMessageType.MethodExecution: break; case SocketMessageType.Identity: ClientIdentificationEvent?.Invoke(this, Guid.Parse(msg.Message)); break; case SocketMessageType.Normal: MessageRecievedEvent?.Invoke(this, msg); break; default: throw new ArgumentOutOfRangeException(); } } Socket.BeginReceive(state.Buffer, 0, state.BufferSize, 0, ReadCallback, state); } else { } } catch (SocketException e) { _logger.Warn(e.Message); } }
public void Is_argument_exception_thrown_when_MethodDeserialization_string_is_null() { MethodSignatureDto.DeserializeMethodObject(null); }
public void Is_jsonserialization_exception_thrown_when_json_array_is_parsed_to_MethodDeserialization() { string invalidJson = "[{\"IsMember\" : true, \"Name\" : \"John\", \"Age\" : 24}]"; MethodSignatureDto.DeserializeMethodObject(invalidJson); }
public void Is_argument_exception_thrown_when_MethodDeserialization_string_is_empty() { string json = ""; MethodSignatureDto.DeserializeMethodObject(json); }
public void Is_jsonreader_exception_thrown_when_MethodDeserialization_string_is_invalid() { string invalidJson = "this is not valid json"; MethodSignatureDto.DeserializeMethodObject(invalidJson); }