Skip to content

Testing request body multiple times fails because stream pointer is at the end of the stream #158

@the-gozo

Description

@the-gozo

example code from top-of-my-head, probably has syntax error, but...

void Setup(string value) 
{  
mockedHttpHandler.When(HttpMethod.Post, "some-url")
      .WithBody<MyClass>(
          r =>
          {
            return r.Value= value
          }
      )
      .RespondJson(_ =>
      {
    
         return new Response()
      }
}

If i configure the same endpoint twice with differenet 'value':

Setup("dog"); 
Setup("cat"); 

then calling the url twice from my test

client.PostAsync(new MyClass{ Value = "dog"});
client.PostAsync(new MyClass{ Value = "cat"});

the JsonContentMatcher during second (cat) call will fail, because its already been matched and run once during the first (dog) evaluation, the content stream has already been read, the pointer is at the end of the stream, hence nothing will be deserialized on line 44 in JsonContentMatcher

var deserializedContent = Deserialize(message.Content.ReadAsStream());

version 7.0.0.

similar issue: #21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions