-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question : Do we have provision to read the Response data from a file? #115
Comments
Hello @raghavendrabankapur This is not yet described in the Wiki (maybe I need to restructure the wiki), but you can use
/// <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 ? 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?
The text was updated successfully, but these errors were encountered: