-
-
Notifications
You must be signed in to change notification settings - Fork 804
Expand file tree
/
Copy pathEntityIdOrDataTest.cs
More file actions
71 lines (60 loc) · 1.78 KB
/
EntityIdOrDataTest.cs
File metadata and controls
71 lines (60 loc) · 1.78 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using HotChocolate.AspNetCore.Tests.Utilities;
using Microsoft.Extensions.DependencyInjection;
using HotChocolate.Types;
namespace StrawberryShake.CodeGeneration.CSharp.Integration.EntityIdOrData;
public class EntityIdOrDataTest : ServerTestBase
{
public EntityIdOrDataTest(TestServerFactory serverFactory) : base(serverFactory)
{
}
[Fact]
public async Task Execute_EntityIdOrData_Test()
{
// arrange
var ct = new CancellationTokenSource(20_000).Token;
var serviceCollection = new ServiceCollection();
serviceCollection
.AddGraphQLServer()
.AddQueryType<Query>()
.AddType<IBar>()
.AddType<Baz>()
.AddType<Baz2>()
.AddType<Quox>()
.AddType<Quox2>();
serviceCollection.AddEntityIdOrDataClient().ConfigureInMemoryClient();
IServiceProvider services = serviceCollection.BuildServiceProvider();
var client = services.GetRequiredService<EntityIdOrDataClient>();
// act
var result = await client.GetFoo.ExecuteAsync(ct);
// assert
result.MatchSnapshot();
}
public class Query
{
public IBar[] GetFoo() =>
[
new Baz { Id = "BarId" },
new Baz2 { Id = "Bar2Id" },
new Quox { Foo = "QuoxFoo" },
new Quox2 { Foo = "Quox2Foo" }
];
}
[UnionType("Bar")]
public interface IBar;
public class Baz : IBar
{
public string Id { get; set; } = null!;
}
public class Baz2 : IBar
{
public string Id { get; set; } = null!;
}
public class Quox : IBar
{
public string Foo { get; set; } = null!;
}
public class Quox2 : IBar
{
public string Foo { get; set; } = null!;
}
}