Skip to content

Commit d464ee2

Browse files
committed
Fixed incorrect ETag tests: header value is a collection, so tests would always succeed
1 parent e9d7f84 commit d464ee2

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

test/OpenApiKiotaEndToEndTests/Headers/ETagTests.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
5555
// Assert
5656
response.Should().BeNullOrEmpty();
5757

58-
headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().NotBeNullOrEmpty();
58+
string[] eTagHeaderValues = headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
59+
eTagHeaderValues.ShouldHaveCount(1);
60+
eTagHeaderValues[0].Should().Match("\"*\"");
5961
}
6062

6163
[Fact]
@@ -85,7 +87,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8587
// Assert
8688
response.ShouldNotBeNull();
8789

88-
headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().NotBeNullOrEmpty();
90+
string[] eTagHeaderValues = headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
91+
eTagHeaderValues.ShouldHaveCount(1);
92+
eTagHeaderValues[0].Should().Match("\"*\"");
8993
}
9094

9195
[Fact]
@@ -126,8 +130,7 @@ public async Task Returns_no_ETag_for_POST_request()
126130
InspectResponseHeaders = true
127131
};
128132

129-
// Act
130-
CountryPrimaryResponseDocument? response = await apiClient.Countries.PostAsync(new CountryPostRequestDocument
133+
var requestBody = new CountryPostRequestDocument
131134
{
132135
Data = new CountryDataInPostRequest
133136
{
@@ -138,7 +141,11 @@ public async Task Returns_no_ETag_for_POST_request()
138141
Population = newCountry.Population
139142
}
140143
}
141-
}, configuration => configuration.Options.Add(headerInspector));
144+
};
145+
146+
// Act
147+
CountryPrimaryResponseDocument? response =
148+
await apiClient.Countries.PostAsync(requestBody, configuration => configuration.Options.Add(headerInspector));
142149

143150
// Assert
144151
response.ShouldNotBeNull();
@@ -183,7 +190,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
183190
ApiException exception = (await action.Should().ThrowExactlyAsync<ApiException>()).Which;
184191
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.NotModified);
185192

186-
headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().Equal([responseETag]);
193+
string[] eTagHeaderValues = headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
194+
eTagHeaderValues.ShouldHaveCount(1);
195+
eTagHeaderValues[0].Should().Be(responseETag);
187196
}
188197

189198
[Fact]
@@ -217,6 +226,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
217226
// Assert
218227
response.ShouldNotBeNull();
219228

220-
headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().NotBeNullOrEmpty();
229+
string[] eTagHeaderValues = headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
230+
eTagHeaderValues.ShouldHaveCount(1);
231+
eTagHeaderValues[0].Should().Match("\"*\"");
221232
}
222233
}

test/OpenApiNSwagEndToEndTests/Headers/ETagTests.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
4747
// Assert
4848
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
4949

50-
response.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().NotBeNullOrEmpty();
50+
string[] eTagHeaderValues = response.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
51+
eTagHeaderValues.ShouldHaveCount(1);
52+
eTagHeaderValues[0].Should().Match("\"*\"");
5153
}
5254

5355
[Fact]
@@ -72,7 +74,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
7274
// Assert
7375
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
7476

75-
response.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().NotBeNullOrEmpty();
77+
string[] eTagHeaderValues = response.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
78+
eTagHeaderValues.ShouldHaveCount(1);
79+
eTagHeaderValues[0].Should().Match("\"*\"");
7680

7781
response.Result.ShouldNotBeNull();
7882
}
@@ -103,19 +107,20 @@ public async Task Returns_no_ETag_for_POST_request()
103107
using HttpClient httpClient = _testContext.Factory.CreateDefaultClient(_logHttpMessageHandler);
104108
var apiClient = new HeadersClient(httpClient);
105109

106-
// Act
107-
ApiResponse<CountryPrimaryResponseDocument?> response = await ApiResponse.TranslateAsync(() => apiClient.PostCountryAsync(null,
108-
new CountryPostRequestDocument
110+
var requestBody = new CountryPostRequestDocument
111+
{
112+
Data = new CountryDataInPostRequest
109113
{
110-
Data = new CountryDataInPostRequest
114+
Attributes = new CountryAttributesInPostRequest
111115
{
112-
Attributes = new CountryAttributesInPostRequest
113-
{
114-
Name = newCountry.Name,
115-
Population = newCountry.Population
116-
}
116+
Name = newCountry.Name,
117+
Population = newCountry.Population
117118
}
118-
}));
119+
}
120+
};
121+
122+
// Act
123+
ApiResponse<CountryPrimaryResponseDocument?> response = await ApiResponse.TranslateAsync(() => apiClient.PostCountryAsync(null, requestBody));
119124

120125
// Assert
121126
response.StatusCode.Should().Be((int)HttpStatusCode.Created);
@@ -152,7 +157,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
152157
// Assert
153158
response2.StatusCode.Should().Be((int)HttpStatusCode.NotModified);
154159

155-
response2.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().Equal([responseETag]);
160+
string[] eTagHeaderValues = response2.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
161+
eTagHeaderValues.ShouldHaveCount(1);
162+
eTagHeaderValues[0].Should().Be(responseETag);
156163

157164
response2.Result.Should().BeNull();
158165
}
@@ -180,7 +187,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
180187
// Assert
181188
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
182189

183-
response.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.Should().NotBeNullOrEmpty();
190+
string[] eTagHeaderValues = response.Headers.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();
191+
eTagHeaderValues.ShouldHaveCount(1);
192+
eTagHeaderValues[0].Should().Match("\"*\"");
184193

185194
response.Result.ShouldNotBeNull();
186195
}

0 commit comments

Comments
 (0)