Skip to content
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

Closed
raghavendrabankapur opened this issue Apr 2, 2018 · 4 comments
Labels

Comments

@raghavendrabankapur
Copy link
Collaborator

raghavendrabankapur commented Apr 2, 2018

@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?

@StefH
Copy link
Collaborator

StefH commented Apr 5, 2018

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);

@raghavendrabankapur
Copy link
Collaborator Author

@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.

@StefH
Copy link
Collaborator

StefH commented Apr 5, 2018

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;
}

@StefH
Copy link
Collaborator

StefH commented Sep 11, 2018

Also this linked issue could help you ?
#173

Closing this issue for now. If you still have question, please reopen or create a new issue.

@StefH StefH closed this as completed Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants