WithBodyFromFile (#56)

This commit is contained in:
Stef Heyenrath
2017-10-25 21:33:57 +02:00
parent 15370a89ca
commit cbe6a0a2b4
16 changed files with 180 additions and 118 deletions

View File

@@ -39,7 +39,7 @@ namespace WireMock.Owin
}
responseMessage.Headers.Where(h => h.Key != HttpKnownHeaderNames.ContentType).ToList().ForEach(pair => response.Headers.Append(pair.Key, pair.Value));
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null)
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null && responseMessage.BodyAsFile == null)
{
return;
}
@@ -49,6 +49,14 @@ namespace WireMock.Owin
await response.Body.WriteAsync(responseMessage.BodyAsBytes, 0, responseMessage.BodyAsBytes.Length);
return;
}
if (responseMessage.BodyAsFile != null)
{
byte[] bytes = File.ReadAllBytes(responseMessage.BodyAsFile);
await response.Body.WriteAsync(bytes, 0, bytes.Length);
return;
}
Encoding encoding = responseMessage.BodyEncoding ?? _utf8NoBom;
using (var writer = new StreamWriter(response.Body, encoding))