How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

前端 未结 3 1997
梦如初夏
梦如初夏 2020-11-28 11:12

.NET Core 2.1 comes with this new factory called HttpClientFactory, but I can\'t figure out how to mock it to unit test some methods that include REST service c

3条回答
  •  旧时难觅i
    2020-11-28 12:06

    This code threw this exception for me, System.InvalidOperationException: The request does not have an associated configuration object or the provided configuration was null.

    So included this in the test method, and it works.

    var configuration = new HttpConfiguration();
    var request = new HttpRequestMessage();
    request.SetConfiguration(configuration);
    

提交回复
热议问题