Closed raghavendrabankapur closed 6 years ago
Hello @raghavendrabankapur
This is not yet described in the Wiki (maybe I need to restructure the wiki), but you can use
BodyAsFile
in the JSON mapping
or
in C# code:
/// <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);
@StefH in that case, the file name should be the full path of the file , or file should be placed somewhere the similar way of __admin/mappings.
As of now, you need to provide the full path. Maybe it's a good idea that the code can support both.
/// <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;
}
Also this linked issue could help you ? https://github.com/WireMock-Net/WireMock.Net/issues/173
Closing this issue for now. If you still have question, please reopen or create a new issue.
@StefH We have a huge data that need to be responded with and also this is been used by other mocks. Can we respond to a matching request with a file content?