WebApplicationFactory stream body read multiple times
Hello here !
We are trying to use
.EnableBuffering
in a WebApplicationFactory/TestHost context (within our XUnit test) and it seems like it's not possible.
Kind of related to this issue : https://github.com/dotnet/aspnetcore/issues/33780
When try to use the HttpClient provided by the WebApplicationFactory we end up having a AsyncStreamWrapper
object, we have a middleware that is using EnablebBuffering
for particular route where we need to read the content multiple time to perform action in a middleware (I can give more context on this if required).
After investigate a little bit further, it looks like the TestHost server just finish the request when the body is read : even if we are using EnableBuffering
.
In first place, we had issue regarding the use of .Seek
against a AsyncStreamWrapper
, we tried to just convert this into a MemoryStream
which was OK for this but we ended up having our middleware/handler not called because we read the body content one time when copy from AsyncStreamWrapper
to MemoryStream
.
So, is this possible in a Test server context to read body content multiple time ?
Thanks in advance !GitHub
TestServer ignores stream position passed through StreamContent · ...
Describe the bug When using TestServer, HttpClient sends the whole stream from the start, the actual position in the stream is ignored. Test below shows passing stream with length = 3 and position ...
1 Reply
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View