Skip to content

Commit 239b68d

Browse files
Copilotxperiandri
andcommitted
Migrate integration tests to in-process hosts via WebApplicationFactory and remove external server orchestration from build (#564)
Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Andrii Chebukin <XperiAndri@Outlook.com>
1 parent 50b4569 commit 239b68d

3 files changed

Lines changed: 152 additions & 358 deletions

File tree

tests/FSharp.Data.GraphQL.IntegrationTests/IntrospectionUpdateTests.fs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,66 @@ let normalizeJsonDocument options (document : JsonDocument) =
2020
JsonDocument.Parse buffer
2121

2222
let parseAndNormalizeJsonAsync ct options stream = task {
23-
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
24-
return normalizeJsonDocument options document
25-
}
23+
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
24+
return normalizeJsonDocument options document
25+
}
2626

2727
let areSchemasEqual (document1 : JsonDocument) (document2 : JsonDocument) =
2828
let schema1 = document1.RootElement.GetProperty("data").GetProperty ("__schema")
2929
let schema2 = document2.RootElement.GetProperty("data").GetProperty ("__schema")
3030
schema1.GetRawText () = schema2.GetRawText ()
3131

3232
let readDestinationDocumentAsync ct (stream : FileStream) = task {
33-
try
34-
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
35-
return ValueSome document
36-
with :? JsonException ->
37-
return ValueNone
38-
}
33+
try
34+
let! document = JsonDocument.ParseAsync (stream, cancellationToken = ct)
35+
return ValueSome document
36+
with :? JsonException ->
37+
return ValueNone
38+
}
3939

4040
let updateIntrospectionFileAsync ct sourceStream = task {
41-
use destinationStream =
42-
new FileStream (introspectionFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)
41+
use destinationStream =
42+
new FileStream (introspectionFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)
4343

4444
let options = JsonWriterOptions (Indented = true)
45-
let! sourceDocument = parseAndNormalizeJsonAsync ct options sourceStream
46-
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
47-
let! destinationDocument = readDestinationDocumentAsync ct destinationStream
45+
let! sourceDocument = parseAndNormalizeJsonAsync ct options sourceStream
46+
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
47+
let! destinationDocument = readDestinationDocumentAsync ct destinationStream
4848

49-
let shouldUpdate =
50-
match destinationDocument with
51-
| ValueNone -> true
52-
| ValueSome document -> not (areSchemasEqual document sourceDocument)
49+
let shouldUpdate =
50+
match destinationDocument with
51+
| ValueNone -> true
52+
| ValueSome document -> not (areSchemasEqual document sourceDocument)
5353

54-
if shouldUpdate then
55-
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
56-
destinationStream.SetLength 0
57-
use writer = new Utf8JsonWriter (destinationStream, options)
58-
sourceDocument.WriteTo writer
59-
writer.Flush ()
54+
if shouldUpdate then
55+
destinationStream.Seek (0L, SeekOrigin.Begin) |> ignore
56+
destinationStream.SetLength 0
57+
use writer = new Utf8JsonWriter (destinationStream, options)
58+
sourceDocument.WriteTo writer
59+
writer.Flush ()
6060

61-
return shouldUpdate
62-
}
61+
return shouldUpdate
62+
}
6363

6464
[<Fact>]
6565
let ``Get GraphQL introspection response returns schema`` () = task {
66-
use httpClient = TestHosts.createIntegrationHttpClient ()
66+
use httpClient = TestHosts.createIntegrationHttpClient ()
6767
let! response = httpClient.GetFromJsonAsync<JsonElement> ("/", CancellationToken.None)
6868
let schema = response.GetProperty("data").GetProperty ("__schema")
6969
Assert.NotEqual (Unchecked.defaultof<JsonElement>, schema)
70-
let hasErrors, _ = response.TryGetProperty "errors"
71-
Assert.False hasErrors
72-
}
70+
let hasErrors, _ = response.TryGetProperty "errors"
71+
Assert.False hasErrors
72+
}
7373

7474
[<Fact>]
7575
let ``Update integration introspection file when schema changes`` () = task {
76-
use httpClient = TestHosts.createIntegrationHttpClient ()
76+
use httpClient = TestHosts.createIntegrationHttpClient ()
7777
let! sourceStream = httpClient.GetStreamAsync ("/")
78-
let! wasUpdated = updateIntrospectionFileAsync CancellationToken.None sourceStream
78+
let! wasUpdated = updateIntrospectionFileAsync CancellationToken.None sourceStream
7979
Assert.True (File.Exists introspectionFilePath)
80-
if wasUpdated then
80+
if wasUpdated then
8181
let! sourceStreamSecondRun = httpClient.GetStreamAsync ("/")
82-
use sourceStreamForVerification = sourceStreamSecondRun
83-
let! wasUpdatedSecondRun = updateIntrospectionFileAsync CancellationToken.None sourceStreamForVerification
84-
Assert.False wasUpdatedSecondRun
85-
}
82+
use sourceStreamForVerification = sourceStreamSecondRun
83+
let! wasUpdatedSecondRun = updateIntrospectionFileAsync CancellationToken.None sourceStreamForVerification
84+
Assert.False wasUpdatedSecondRun
85+
}

0 commit comments

Comments
 (0)