private void ShouldContain(string value) { if (StringContent.Contains(value, StringComparison.InvariantCultureIgnoreCase) == false) { throw new BardException($"The received response did not contain the message:{value}"); } }
private void ShouldContain(string value) { if (StringContent.Contains(value) == false) { throw new BardException($"The received response did not contain the message:{value}"); } }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { /* serialize and send request */ byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request)); await websocket.SendAsync(new ArraySegment <byte>(data), WebSocketMessageType.Binary, true, cancellationToken); /* recieve and reconstruct response headers */ HttpResponseMessage response = await RecieveAndParse <HttpResponseMessage>(cancellationToken); /* recieve and reconstruct response content headers */ KeyValuePair <string, string[]>[] contentHeaders = await RecieveAndParse <KeyValuePair <string, string[]>[]>(cancellationToken); /* apply headers to temp object */ HttpContentHeaders tempHeaders = new StringContent("").Headers; ReplaceHeaders(tempHeaders, contentHeaders); /* recieve content */ if (tempHeaders.Contains("Content-Length")) { /* large data case */ int length = int.Parse(tempHeaders.GetValues("Content-Length").First()); response.Content = new StreamContent(new WebsocketResultStream(length, websocket)); } else { /* small data case */ WebSocketReceiveResult websocketResponse = await websocket.ReceiveAsync(new ArraySegment <byte>(responseBuffer), cancellationToken); List <byte> rawBody = new List <byte>(); rawBody.AddRange(responseBuffer.Take(websocketResponse.Count)); while (!websocketResponse.EndOfMessage) { websocketResponse = await websocket.ReceiveAsync(new ArraySegment <byte>(responseBuffer), cancellationToken); rawBody.AddRange(responseBuffer.Take(websocketResponse.Count)); } response.Content = new ByteArrayContent(rawBody.ToArray()); } /* apply headers to final content */ ReplaceHeaders(response.Content.Headers, contentHeaders); return(response); }