-
-
Notifications
You must be signed in to change notification settings - Fork 804
Expand file tree
/
Copy pathAnyScalarDefaultSerializationTest.cs
More file actions
49 lines (43 loc) · 1.85 KB
/
AnyScalarDefaultSerializationTest.cs
File metadata and controls
49 lines (43 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using HotChocolate;
using HotChocolate.AspNetCore.Tests.Utilities;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
using StrawberryShake.Transport.WebSockets;
namespace StrawberryShake.CodeGeneration.CSharp.Integration.AnyScalarDefaultSerialization;
public class AnyScalarDefaultSerializationTest : ServerTestBase
{
public AnyScalarDefaultSerializationTest(TestServerFactory serverFactory) : base(serverFactory)
{
}
[Fact]
public async Task Execute_AnyScalarDefaultSerialization_Test()
{
// arrange
using var cts = new CancellationTokenSource(20_000);
using var host = TestServerHelper.CreateServer(
builder => builder.AddTypeExtension<QueryResolvers>().AddJsonTypeConverter(),
out var port);
var serviceCollection = new ServiceCollection();
serviceCollection.AddHttpClient(
AnyScalarDefaultSerializationClient.ClientName,
c => c.BaseAddress = new Uri("http://localhost:" + port + "/graphql"));
serviceCollection.AddWebSocketClient(
AnyScalarDefaultSerializationClient.ClientName,
c => c.Uri = new Uri("ws://localhost:" + port + "/graphql"));
serviceCollection.AddAnyScalarDefaultSerializationClient();
IServiceProvider services = serviceCollection.BuildServiceProvider();
var client =
services.GetRequiredService<AnyScalarDefaultSerializationClient>();
// act
var result = await client.GetJson.ExecuteAsync(cts.Token);
// assert
Assert.Empty(result.Errors);
result.Data?.Json.ToString().MatchSnapshot();
}
[ExtendObjectType(OperationTypeNames.Query)]
public class QueryResolvers
{
[GraphQLType(typeof(NonNullType<AnyType>))]
public Dictionary<string, object> GetJson() => new() { { "abc", "def" } };
}
}