c# UnitTesting Test that API call was made

458 Views Asked by At

I am writing unit test for a simple function

public async Task<HttpResponseMessage> MakeRestCallAsync(Uri uri, string input)
{
    using (httpClient = new HttpClient())
    {
        using (var formData = new MultipartFormDataContent())
        {
            //add content to form data
            formData.Add(new StringContent(input), "Input");
            return await httpClient.PostAsync(uri, formData);          
        }
    }
}

I would like to test that httpClient fired the PostAsync I am using Microsoft.VisualStudio.TestTools.UnitTesting for the test project Can't find a proper way to do that Also if possible I would like to test that the call was actually made with the passed URI and passed input

0

There are 0 best solutions below