graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Be able to provide http and websocket client to strawberry shake

Open kolpav opened this issue 3 years ago • 4 comments

Is your feature request related to a problem?

I am using WebApplicationFactory for integration testing which uses its own in memory http client and I have to register IHttpClientFactory to make strawberry shake to use client from web factory instead of its own client which was not straight forward. I was not able to do the same for web sockets.

The solution you'd like

  • Ideally be able to pass both clients to strawberry shake via constructor to cover to most likely scenario by looking through other people's code it seems fixture dependencies are mostly instantiated manually rather than resolved via fixture own DI
  • Make strawberry shake play nice with what is described in Integration tests in ASP.NET Core as this is how I ended up using strawberry shake client

Product

Strawberry Shake

Edit:

In the end I was able to provide my own web socket implementation by copy pasting web socket client from HC and hardcoding its values as implementing IWebSocketClient is not something I would be able to do.

kolpav avatar Feb 12 '22 06:02 kolpav

I think this issue can be closed. Strawberry Shake contains an extension method ConfigureHttpClient where the second parameter is the .net http client builder. This builder can be used to inject the http message handler for the test server.


 var serviceCollection = new ServiceCollection();

// overriding the strawberry shake client with the client middleware from WebApplicationFactory
serviceCollection.AddSomeClient().ConfigureHttpClient(c =>
{
    c.BaseAddress = new Uri(factory.Server.BaseAddress, "graphql");
}, c =>
{
    c.ConfigurePrimaryHttpMessageHandler(() => factory.Server.CreateHandler());
});

var client = serviceCollection.BuildServiceProvider().GetRequiredService<ISomeClient>();

jarlef avatar Jun 23 '23 21:06 jarlef

Websocket client is the one which is hard to provide your own implementation for.

kolpav avatar Jun 27 '23 08:06 kolpav

@kolpav would you mind sharing some code, please? I got the HttpClient working with WebApplicationFactory but I'm unable to get the WebSocket client to work.

rolfwessels avatar Jan 30 '24 12:01 rolfwessels

@rolfwessels At the time I think I just copy-pasted whatever is implementing IWebSocketClient in HC and hardcoded my own values. Even if I could find the code it would be unusable now.

kolpav avatar Feb 07 '24 20:02 kolpav