mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 18:28:27 +02:00
WithBodyFromFile (#56)
This commit is contained in:
@@ -9,14 +9,6 @@ namespace WireMock.ResponseBuilders
|
||||
/// </summary>
|
||||
public interface IBodyResponseBuilder : ITransformResponseBuilder
|
||||
{
|
||||
///// <summary>
|
||||
///// WithBody : Create a string response based on a string.
|
||||
///// </summary>
|
||||
///// <param name="body">The body.</param>
|
||||
///// <param name="encoding">The body encoding.</param>
|
||||
///// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
//// IResponseBuilder WithBody([NotNull] string body, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a ... response based on a string.
|
||||
/// </summary>
|
||||
@@ -51,5 +43,13 @@ namespace WireMock.ResponseBuilders
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
[Obsolete]
|
||||
IResponseBuilder WithBodyFromBase64([NotNull] string bodyAsbase64, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBodyFromFile : Create a ... response based on a File.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <param name="cache">Defines if this file is cached in memory or retrieved from disk everytime the response is created.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBodyFromFile([NotNull] string filename, bool cache = true);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -139,11 +140,7 @@ namespace WireMock.ResponseBuilders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The headers.</param>
|
||||
/// <returns></returns>
|
||||
/// <inheritdoc cref="IHeadersResponseBuilder.WithHeaders"/>
|
||||
public IResponseBuilder WithHeaders(IDictionary<string, string> headers)
|
||||
{
|
||||
ResponseMessage.Headers = headers;
|
||||
@@ -175,6 +172,30 @@ namespace WireMock.ResponseBuilders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyFromFile"/>
|
||||
public IResponseBuilder WithBodyFromFile(string filename, bool cache = true)
|
||||
{
|
||||
Check.NotNull(filename, nameof(filename));
|
||||
|
||||
ResponseMessage.BodyEncoding = null;
|
||||
ResponseMessage.BodyAsFileIsCached = cache;
|
||||
|
||||
if (cache)
|
||||
{
|
||||
ResponseMessage.Body = null;
|
||||
ResponseMessage.BodyAsBytes = File.ReadAllBytes(filename);
|
||||
ResponseMessage.BodyAsFile = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResponseMessage.Body = null;
|
||||
ResponseMessage.BodyAsBytes = null;
|
||||
ResponseMessage.BodyAsFile = filename;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(string, string, Encoding)"/>
|
||||
public IResponseBuilder WithBody(string body, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user