0

I have a function

private async Task callApi(string baseAddress, string endpoint, Log log)
{
    var client = new HttpClient();
    HttpContent content = new StringContent(JsonConvert.SerializeObject(log), Encoding.UTF8, "application/json");
    client.BaseAddress = new Uri(baseAddress);
    await client.PostAsync(endpoint, content);
    client.Dispose();
}

This works when deployed but I've written a test to make sure it works. However when the test runs, the call is never made.

If I change the line

await client.PostAsync(endpoint, content);

To

_ = client.PostAsync(endpoint, content).Result;

Then it does work, but I want to avoid using Result as it can cause blockages.

Edit: It's worth mentioning I don't care about the result of the call. It's should be sent and then the result doesn't matter to me.

Jack Tyler
  • 509
  • 6
  • 18

1 Answers1

0

@Gabriel Luci was correct with his

comment Sounds like your test is not using await when it calls callApi

I change the pipeline so that it returned a Task instead of void and awaited the call. This now works. Thanks!

Jack Tyler
  • 509
  • 6
  • 18