public void GetResponseAsync() { "发送消息之后,能等待收到对应的回复".Test(() => { var responseManager = new ResponseManager(); var requestByteList = new byte[] { 0xFF, 0xFE }; var request = new IpcRequestMessage("Tests", new IpcBufferMessage(requestByteList)); var ipcClientRequestMessage = responseManager.CreateRequestMessage(request); Assert.AreEqual(false, ipcClientRequestMessage.Task.IsCompleted); var requestStream = IpcBufferMessageContextToStream(ipcClientRequestMessage.IpcBufferMessageContext); IpcClientRequestArgs ipcClientRequestArgs = null; responseManager.OnIpcClientRequestReceived += (sender, args) => { ipcClientRequestArgs = args; }; Assert.IsNotNull(requestStream); responseManager.OnReceiveMessage(new PeerMessageArgs("Foo", requestStream, ack: 100, IpcMessageCommandType.RequestMessage)); Assert.IsNotNull(ipcClientRequestArgs); var responseByteList = new byte[] { 0xF1, 0xF2 }; var responseMessageContext = responseManager.CreateResponseMessage(ipcClientRequestArgs.MessageId, new IpcBufferMessage(responseByteList), "Tests"); var responseStream = IpcBufferMessageContextToStream(responseMessageContext); responseManager.OnReceiveMessage(new PeerMessageArgs("Foo", responseStream, ack: 100, IpcMessageCommandType.ResponseMessage)); Assert.AreEqual(true, ipcClientRequestMessage.Task.IsCompleted); }); }
private void ResponseManager_OnIpcClientRequestReceived(object?sender, IpcClientRequestArgs e) { var ipcRequestHandlerProvider = IpcContext.IpcRequestHandlerProvider; ipcRequestHandlerProvider.HandleRequest(this, e); }