Repository navigation
How to test multipart? #2354
|
I'm rewriting our client generator to use Refit (via Refitter). I'm using |
Replies: 1 comment
|
Turn off var parts = new Dictionary<string, string>();
var http = new StubHttp
{
{ Route.Post("/upload"), Reply.From(async request =>
{
var multipart = (MultipartFormDataContent)request.Content!;
foreach (var part in multipart)
parts[part.Headers.ContentDisposition!.Name!] = await part.ReadAsStringAsync();
return new HttpResponseMessage(HttpStatusCode.OK);
}) },
};
http.RequestCapture = RequestCapture.None;
var api = http.CreateClient<IUploadApi>("https://api.test");
await api.Upload(new StreamPart(stream, "a.txt", "text/plain"), "my file");
Assert.Equal("my file", parts["description"]);With the default capture, For a file part, Checked on Refit and Refit.Testing 16.3.0. |
Turn off
StubHttp's body capture and read the parts insideReply.From, while the request's still alive: