Open kolpav opened 2 years ago
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>();
Websocket client is the one which is hard to provide your own implementation for.
@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 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.
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 registerIHttpClientFactory
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
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.