Skip to content

Commit 90d02eb

Browse files
committed
SampleWeb
1 parent 328cc57 commit 90d02eb

3 files changed

Lines changed: 28 additions & 19 deletions

File tree

src/SampleWeb.Tests/GlobalUsings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
global using GraphQL.EntityFramework.Testing;
1+
global using GraphQL.EntityFramework;
2+
global using GraphQL.EntityFramework.Testing;
23
global using GraphQL.Types;
34
global using GraphQL.Utilities;
4-
global using Microsoft.AspNetCore.Hosting;
55
global using Microsoft.AspNetCore.TestHost;
66
global using Microsoft.Extensions.DependencyInjection;
77
global using Microsoft.Extensions.Logging;

src/SampleWeb.Tests/GraphQlControllerTests.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System.Net;
1+
using System.Net;
2+
using Microsoft.AspNetCore.Mvc.Testing;
23
using Newtonsoft.Json;
34
// ReSharper disable PrivateFieldCanBeConvertedToLocalVariable
4-
#pragma warning disable ASPDEPR008
5-
#pragma warning disable ASPDEPR004
65

76
#region GraphQlControllerTests
87

@@ -14,9 +13,9 @@ public class GraphQlControllerTests
1413

1514
static GraphQlControllerTests()
1615
{
17-
var server = GetTestServer();
18-
client = server.CreateClient();
19-
webSocket = server.CreateWebSocketClient();
16+
var factory = new WebApplicationFactory<Program>();
17+
client = factory.CreateClient();
18+
webSocket = factory.Server.CreateWebSocketClient();
2019
webSocket.ConfigureRequest =
2120
request =>
2221
{
@@ -240,13 +239,6 @@ public async Task Complex_query_result()
240239
response.EnsureSuccessStatusCode();
241240
await Verify(result);
242241
}
243-
244-
static TestServer GetTestServer()
245-
{
246-
var builder = new WebHostBuilder();
247-
builder.UseStartup<Startup>();
248-
return new(builder);
249-
}
250242
}
251243

252-
#endregion
244+
#endregion

src/SampleWeb.Tests/SchemaPrint.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using GraphQL;
1+
using GraphQL;
2+
using GraphQL.Types;
23

34
public class SchemaPrint
45
{
@@ -7,11 +8,27 @@ public async Task Print()
78
{
89
var services = new ServiceCollection();
910
services.AddSingleton<ILoggerFactory>(_ => NullLoggerFactory.Instance);
10-
new Startup().ConfigureServices(services);
11+
12+
EfGraphQLConventions.RegisterInContainer<SampleDbContext>(
13+
services,
14+
model: SampleDbContext.StaticModel);
15+
16+
foreach (var type in typeof(Program).Assembly
17+
.GetTypes()
18+
.Where(_ => !_.IsAbstract &&
19+
(_.IsAssignableTo(typeof(IObjectGraphType)) ||
20+
_.IsAssignableTo(typeof(IInputObjectGraphType)))))
21+
{
22+
services.AddSingleton(type);
23+
}
24+
25+
services.AddSingleton<IDocumentExecuter, EfDocumentExecuter>();
26+
services.AddSingleton<ISchema, Schema>();
27+
services.AddGraphQL(null);
1128

1229
await using var provider = services.BuildServiceProvider();
1330
var schema = provider.GetRequiredService<ISchema>();
1431
var print = schema.Print();
1532
await Verify(print);
1633
}
17-
}
34+
}

0 commit comments

Comments
 (0)