I need to replace strawberry shake web socket client with asp .net test server one for end to end testing is it possible? I was able to replace http client which used for queries and mutations with test server one by registering IHttpClientFactory
but I don't know how to do the same for web sockets.

- 912
- 2
- 9
- 24
-
Yes, that is possible. We also have an in-memory client that is intended for integration testing. – Michael Ingmar Staib Feb 15 '22 at 18:37
-
@MichaelIngmarStaib Please show me how I have read HC source code along with its tests and I am still unsure how to do it. I need to make strawberry shake to use web socket client coming from `WebApplicationFactory`. I am doing end to end testing of my server (I used wrong term in my now edited question) making requests as a client would and asserting responses. I am trying to avoid mocking as much as possible so the test are as close as possible to real application. I can provide minimal repo if answer is too long or complicated. – Hnus Feb 20 '22 at 07:13
1 Answers
The best way I've found to test with HC and Strawberry Shake is to use the in-memory client and test against the HC GraphQL server directly, rather than using the WebApplicationFactory
. This has the benefit of preserving the async
flow, although you won't be able to test ASP specific things like authentication this way.
Add a reference to the in-memory client.
<PackageReference Include="StrawberryShake.Transport.InMemory" Version="12.6.0" />
In graphqlrc.json
modify your default transport profile (or add a new one, more work to explain).
"transportProfiles": [
{
"name": "Default",
"default": "InMemory",
"subscription": "InMemory"
}
]
Now when you configure your IServiceCollection
services
.AddGraphQL()
.BuildDefaultSchema();
services
.AddGraphQLTestClient()
.ConfigureInMemoryClient();
Where BuildDefaultSchema
is specific to you (i.e. this is how you configure the IRequestExecutorBuilder
). And the name of the method AddGraphQLTestClient
will vary depending on what you called your client in graphqlrc.json
.
That's basically it. Resolve your Strawberry Shake client and it will just work.

- 9,407
- 5
- 63
- 81