-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathAttendeeTests.cs
85 lines (74 loc) · 2.61 KB
/
AttendeeTests.cs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using ConferencePlanner.GraphQL.Data;
using CookieCrumble;
using HotChocolate.Execution;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
using Testcontainers.PostgreSql;
using Testcontainers.Redis;
namespace GraphQL.Tests;
public sealed class AttendeeTests : IAsyncLifetime
{
private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder()
.WithImage("postgres:17.2")
.Build();
private readonly RedisContainer _redisContainer = new RedisBuilder()
.WithImage("redis:7.4")
.Build();
private IRequestExecutor _requestExecutor = null!;
public async ValueTask InitializeAsync()
{
// Start test containers.
await Task.WhenAll(_postgreSqlContainer.StartAsync(), _redisContainer.StartAsync());
// Build request executor.
_requestExecutor = await new ServiceCollection()
.AddDbContext<ApplicationDbContext>(
options => options.UseNpgsql(_postgreSqlContainer.GetConnectionString()))
.AddGraphQLServer()
.AddGlobalObjectIdentification()
.AddMutationConventions()
.AddDbContextCursorPagingProvider()
.AddPagingArguments()
.AddFiltering()
.AddSorting()
.AddRedisSubscriptions(
_ => ConnectionMultiplexer.Connect(_redisContainer.GetConnectionString()))
.AddGraphQLTypes()
.BuildRequestExecutorAsync();
// Create database.
var dbContext = _requestExecutor.Services
.GetApplicationServices()
.GetRequiredService<ApplicationDbContext>();
await dbContext.Database.EnsureCreatedAsync();
}
[Fact]
public async Task RegisterAttendee()
{
// Arrange & act
var result = await _requestExecutor.ExecuteAsync(
"""
mutation RegisterAttendee {
registerAttendee(
input: {
firstName: "Michael"
lastName: "Staib"
username: "michael"
emailAddress: "[email protected]"
}
) {
attendee {
id
}
}
}
""",
TestContext.Current.CancellationToken);
// Assert
result.MatchSnapshot(extension: ".json");
}
public async ValueTask DisposeAsync()
{
await _postgreSqlContainer.DisposeAsync();
await _redisContainer.DisposeAsync();
}
}