@@ -14,6 +14,7 @@ open Microsoft.AspNetCore.Hosting
1414open Microsoft.AspNetCore .TestHost
1515open Microsoft.AspNetCore .Builder
1616open Microsoft.Extensions .DependencyInjection
17+ open Microsoft.Extensions .Hosting
1718open Xunit
1819open NSubstitute
1920open Giraffe
@@ -94,10 +95,22 @@ let createHost
9495 ( configureServices : IServiceCollection -> unit )
9596 ( args : 'Tuple )
9697 =
98+ #if NET10_ 0_ OR_ GREATER
99+ HostBuilder()
100+ .ConfigureWebHost( fun webHostBuilder ->
101+ webHostBuilder
102+ .UseTestServer()
103+ .UseContentRoot( Path.GetFullPath( " TestFiles" ))
104+ .Configure( Action< IApplicationBuilder>( configureApp args))
105+ .ConfigureServices( Action< IServiceCollection> configureServices)
106+ |> ignore
107+ )
108+ #else
97109 ( WebHostBuilder())
98110 .UseContentRoot( Path.GetFullPath( " TestFiles" ))
99111 .Configure( Action< IApplicationBuilder>( configureApp args))
100112 .ConfigureServices( Action< IServiceCollection> configureServices)
113+ #endif
101114
102115let mockJson ( ctx : HttpContext ) =
103116
@@ -131,7 +144,15 @@ let createRequest (method: HttpMethod) (path: string) =
131144
132145let makeRequest configureApp configureServices args ( request : HttpRequestMessage ) =
133146 task {
147+ #if NET10_ 0_ OR_ GREATER
148+ // https://github.com/aspnet/Announcements/issues/526
149+ let host = createHost configureApp configureServices args |> _. Build()
150+
151+ let! _ = host.StartAsync()
152+ use server = host.GetTestServer()
153+ #else
134154 use server = new TestServer( createHost configureApp configureServices args)
155+ #endif
135156 use client = server.CreateClient()
136157 let! response = request |> client.SendAsync
137158 return response
0 commit comments