Skip to content

Commit 83e0b96

Browse files
committed
test(request): assert all sequential json objects was read
1 parent 2f52dac commit 83e0b96

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

tests/Example.OpenApi32.IntegrationTests/ImportFooEventsTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Net;
2-
using System.Net.Mime;
32
using AwesomeAssertions;
43
using OpenAPI.IntegrationTestHelpers.Auth;
54

@@ -22,6 +21,10 @@ public async Task ImportingFooEvents_ShouldReturnAccepted()
2221
{ "Name": "another test" }
2322
""", "application/jsonl")
2423
}, CancellationToken);
24+
2525
result.StatusCode.Should().Be(HttpStatusCode.Accepted);
26+
result.Headers.Should().HaveCount(1);
27+
result.Headers.GetValues("ImportedEvents")
28+
.Should().HaveCount(1).And.AllBe("2");
2629
}
2730
}

tests/Example.OpenApi32/Paths/FooFooIdEvents/Post/Operation.Handler.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ internal partial async Task<Response> HandleAsync(Request request, CancellationT
99
{
1010
throw new InvalidOperationException("missing content, this cannot occur");
1111
}
12+
13+
var importedEvents = 0;
1214
while (await content.MoveNextAsync()
1315
.ConfigureAwait(false))
1416
{
@@ -18,8 +20,15 @@ internal partial async Task<Response> HandleAsync(Request request, CancellationT
1820
throw new InvalidOperationException("Invalid item");
1921
}
2022
_ = content.Current;
23+
importedEvents++;
2124
}
2225

23-
return new Response.Accepted202();
26+
return new Response.Accepted202
27+
{
28+
Headers = new Response.Accepted202.ResponseHeaders
29+
{
30+
ImportedEvents = importedEvents
31+
}
32+
};
2433
}
2534
}

tests/Example.OpenApi32/openapi.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@
9696
},
9797
"responses": {
9898
"202": {
99-
"description": "Accepted"
99+
"description": "Accepted",
100+
"headers": {
101+
"ImportedEvents": {
102+
"description": "Number of events imported",
103+
"schema": {
104+
"type": "integer"
105+
},
106+
"required": true
107+
}
108+
}
100109
}
101110
}
102111
},

0 commit comments

Comments
 (0)