コード例 #1
0
        public void Respond(IPactResponseDefinition response)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }
            if (stream == null)
            {
                throw new InvalidOperationException("Stream is disposed.");
            }
            const string crlf = "\r\n";

            using (var writer = new StreamWriter(stream, Encoding.ASCII))
            {
                var status = (HttpStatusCode)response.ResponseStatusCode.GetValueOrDefault(200);
                writer.Write($"HTTP/1.1 {(int)status} {status}{crlf}");
                foreach (var header in response.ResponseHeaders)
                {
                    writer.Write($"{header.Key}: {header.Value}{crlf}");
                }
                writer.Write(crlf);
                if (response.ResponseBody != null)
                {
                    writer.Write(response.ResponseBody.Render());
                }
                writer.Flush();
                writer.Dispose();
            }
        }
コード例 #2
0
 public PactResponseJsonRenderer(IPactResponseDefinition pact)
 {
     _pact = pact;
 }