title: Mocking httpclient multiple times in a single Unit Test
body: <p>Hi I am trying to mock the httpclient, obviously forcing it to give me the result I need. <strong>The problem</strong> is, that in my unit test I have to <strong>mock the httpClient twice</strong>, each with a different response.</p>
  
  <pre><code>...
  ...
              var httpReq = new HttpRequestMessage(
              HttpMethod.Get,
              $"{config["MY_TEST_ENDPOINT"]/site1}");
  
              var myContent = await response.Content.ReadAsStringAsync();
              var myFirstModel = JsonConvert.DeserializeObject&lt;MyFirstModel&gt;(myContent );
  ...
  ...
  </code></pre>
  
  <p>which I mock this may:</p>
  
  <pre><code>...
  myMockedHttp
              .Protected()
              .Setup&lt;Task&lt;HttpResponseMessage&gt;&gt;(
                  "SendAsync",
                  ItExpr.IsAny&lt;HttpRequestMessage&gt;(),
                  ItExpr.IsAny&lt;CancellationToken&gt;())
              .ReturnsAsync(new HttpResponseMessage()
              {
                  StatusCode = HttpStatusCode.OK,
                  Content = new StringContent("[{'id':'0001'," +
                                              "'name':'Jonah'," +
                                              "'street':'Cambridge Street 1234'}]"
                                              )
              })
              .Verifiable();
  </code></pre>
  
  <p>That will give me a response, that I can deserialize and use - giving it an object with 3 members: id, name and street.</p>
  
  <p>And here comes the problem for me - I also in the same unit test have another httpclient-call, but I don't know how to mock it. It goes like this:</p>
  
  <pre><code>...
  ...
              var httpReq = new HttpRequestMessage(
              HttpMethod.Get,
              $"{config["MY_TEST_ENDPOINT"]/site2}");
  
              var httpResponseMsg = await _httpClient.SendAsync(httpReq);
  
              var myContent = await response.Content.ReadAsStringAsync();
              var myFirstModel = JsonConvert.DeserializeObject&lt;MySecondModel&gt;(myContent );
  ...
  ...
  </code></pre>
  
  <p>And initially - if it was the only httpclient-call, I would mock it like this:</p>
  
  <pre><code>...
  myMockedHttp
              .Protected()
              .Setup&lt;Task&lt;HttpResponseMessage&gt;&gt;(
                  "SendAsync",
                  ItExpr.IsAny&lt;HttpRequestMessage&gt;(),
                  ItExpr.IsAny&lt;CancellationToken&gt;())
              .ReturnsAsync(new HttpResponseMessage()
              {
                  StatusCode = HttpStatusCode.OK,
                  Content = new StringContent("[{'id':'34'," +
                                              "'insurance':'Etx'," +
                                              "'insider':'daily'," +
                                              "'collectives':'4'}]"
                                              )
              })
              .Verifiable();
  ...
  ...
  </code></pre>
  
  <p>But obviously I cant... The thing is, I have never tried this situation where I have multiple httpclient-calls that needs to be mocked. As you can see, they respond with different Content, since they are different objects and needs to be handled that way.</p>
  
  <p>Do anyone have any idea how to fix this?</p>