private async Task StartBatching(CancellationToken token) { using (var buff = new MemoryStream()) while (await _batchBlock.OutputAvailableAsync(token)) { if (!_batchBlock.TryReceive(out var chunk)) { continue; } var keys = new byte[chunk.Length][]; for (var i = 0; i < chunk.Length; i++) { buff.SetLength(0); ProtoBuf.Serializer.Serialize(buff, chunk[i]); keys[i] = buff.ToArray(); } var message = new RequestMessageModel() { Keys = keys }; using (var send = _streamFactory.Create()) { ProtoBuf.Serializer.Serialize(send, message); await _client.SendAsync(send, token); } } }
private async Task <string> SendAndReceiveMessageAsync(Message message) { string sentJson = string.Empty; _mockWebSocketClient .Setup(wsc => wsc.SendAsync(It.IsAny <string>())) .Callback <string>(json => sentJson = json); await _sut.SendAsync(message); return(sentJson); }