private async void MazeServerOnRequestReceived(object sender, MazeRequestReceivedEventArgs e) { var context = new WebSocketMazeContext(e) { RequestServices = new AutofacServiceProvider(_container), Connection = new WebSocketConnectionInfo(_connector) }; await _container.Resolve <IMazeRequestExecuter>().Execute(context, _mazeServer); await _mazeServer.FinishResponse(e); }
public async Task ExecuteTest() { var dataStream = new MemoryStream(); var requestSocket = new MazeSocket(dataStream, keepAliveInterval: null); var requestServer = new MazeServer(requestSocket, PackageSize, MaxHeaderSize, ArrayPool <byte> .Shared); var request = GetRequest(); var requestTask = requestServer.SendRequest(request, CancellationToken.None); //will wait for a response await Task.Delay(20); dataStream.Position = 0; var receiverSocket = new MazeSocket(dataStream, null); var receiverServer = new MazeServer(receiverSocket, PackageSize, MaxHeaderSize, ArrayPool <byte> .Shared); var completionSource = new TaskCompletionSource <MazeRequestReceivedEventArgs>(); receiverServer.RequestReceived += (sender, args) => completionSource.SetResult(args); try { await receiverSocket.ReceiveAsync(); } catch (WebSocketException) //EOF { } var result = await completionSource.Task; await AssertReceivedRequest(request, result.Request); dataStream.SetLength(0); await WriteResponse(result.Response); await receiverServer.FinishResponse(result); dataStream.Seek(0, SeekOrigin.Begin); try { await requestSocket.ReceiveAsync(); } catch (WebSocketException) //EOF { } var response = await requestTask; await AssertReceivedResponse(result.Response, response); }