djmnz / RestFluencing

MIT License
11 stars 4 forks source link

Incompatible with .NET Core integration tests #8

Open mweatherill opened 5 years ago

mweatherill commented 5 years ago

RestFluencing doesn't seem to work with .NET Core Integration Tests. It appears that all HTTP requests go over the network rather than direct to the in-memory test server.

I see that a HttpClient is constructed directly in src/restfluencing.Core/Client/HttpClientWrapper/HttpClient.cs:

        public IApiClientResponse ExecuteRequest(IApiClientRequest request)
        {
            using (HttpClient client = new HttpClient())
            {

I need to be able to pass in my own instance of HttpClient.

djmnz commented 5 years ago

@mweatherill you can write your own wrapper.

Have a look on: https://github.com/djmnz/RestFluencing/tree/master/src/restfluencing.Core/Client/HttpClientWrapper

  1. Create your Client
  2. Create your Factory to create a request and client
  3. Set your RestConfiguration to use the new factory you created
config.ClientFactory = new HttpApiClientBuilder();

Let us know if doesn't work.

djmnz commented 5 years ago

@mweatherill just merged the package to be compatible with .Net standard, first step to make it more compatible with those integration tests.

For the moment, I have added a extension that will help you leverage the client factory:

var config = new RestConfiguration();
var client = new HttpClient();
config.UsingWebApiClient(client);

You may still need to manually set the base url to the local server.

I will be building a AspNetMvc package to leverage the factory directly.