@@ -3,25 +3,40 @@ module FSharp.Data.GraphQL.IntegrationTests.TestHosts
33open FSharp.Data .GraphQL
44open Microsoft.AspNetCore .Mvc .Testing
55open System.Net .Http
6+ open System
67
78type IntegrationServerApplicationFactory () =
89 inherit WebApplicationFactory< FSharp.Data.GraphQL.IntegrationTests.Server.Startup> ()
910
1011type StarWarsApplicationFactory () =
1112 inherit WebApplicationFactory< FSharp.Data.GraphQL.Samples.StarWarsApi.Startup> ()
1213
14+ let private integrationFactory = lazy ( new IntegrationServerApplicationFactory ())
15+ let private starWarsFactory = lazy ( new StarWarsApplicationFactory ())
16+
1317let private integrationClient : Lazy < HttpClient > =
14- lazy
15- ( let factory = new IntegrationServerApplicationFactory ()
16- factory.CreateClient ())
18+ lazy ( integrationFactory.Value.CreateClient ())
1719
1820let private starWarsClient : Lazy < HttpClient > =
19- lazy
20- ( let factory = new StarWarsApplicationFactory ()
21- factory.CreateClient ())
21+ lazy ( starWarsFactory.Value.CreateClient ())
22+
23+ do
24+ AppDomain.CurrentDomain.ProcessExit.Add( fun _ ->
25+ if integrationClient.IsValueCreated then
26+ integrationClient.Value.Dispose ()
27+
28+ if starWarsClient.IsValueCreated then
29+ starWarsClient.Value.Dispose ()
30+
31+ if integrationFactory.IsValueCreated then
32+ integrationFactory.Value.Dispose ()
33+
34+ if starWarsFactory.IsValueCreated then
35+ starWarsFactory.Value.Dispose ())
2236
2337let integrationServerUrl = integrationClient.Value.BaseAddress.ToString() .TrimEnd '/'
2438let starWarsServerUrl = starWarsClient.Value.BaseAddress.ToString() .TrimEnd '/'
2539
2640let createIntegrationConnection () = new GraphQLClientConnection ( integrationClient.Value)
2741let createStarWarsConnection () = new GraphQLClientConnection ( starWarsClient.Value)
42+ let createIntegrationHttpClient () = integrationFactory.Value.CreateClient ()
0 commit comments