Skip to content

Commit 46a2892

Browse files
committed
Add assertion on exception message in kiota tests, fix etag error assertions
1 parent d475f8c commit 46a2892

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

test/OpenApiKiotaEndToEndTests/ClientIdGenerationModes/ClientIdGenerationModesTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public async Task Cannot_create_resource_without_ID_when_supplying_ID_is_require
5656
// Assert
5757
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
5858
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
59+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
5960
exception.Errors.ShouldHaveCount(1);
6061

6162
ErrorObject error = exception.Errors[0];
@@ -218,6 +219,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
218219
// Assert
219220
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
220221
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.Conflict);
222+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
221223
exception.Errors.ShouldHaveCount(1);
222224

223225
ErrorObject error = exception.Errors.ElementAt(0);

test/OpenApiKiotaEndToEndTests/Headers/ETagTests.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
9696
public async Task Returns_no_ETag_for_failed_GET_request()
9797
{
9898
// Arrange
99+
string unknownCountryId = Unknown.StringId.For<Country, Guid>();
100+
99101
using HttpClientRequestAdapter requestAdapter = _requestAdapterFactory.CreateAdapter(_testContext.Factory);
100102
var apiClient = new HeadersClient(requestAdapter);
101103

@@ -105,13 +107,19 @@ public async Task Returns_no_ETag_for_failed_GET_request()
105107
};
106108

107109
// Act
108-
Func<Task<CountryPrimaryResponseDocument?>> action = () => apiClient.Countries[Unknown.StringId.For<Country, Guid>()]
109-
.GetAsync(configuration => configuration.Options.Add(headerInspector));
110+
Func<Task<CountryPrimaryResponseDocument?>> action = () =>
111+
apiClient.Countries[unknownCountryId].GetAsync(configuration => configuration.Options.Add(headerInspector));
110112

111113
// Assert
112114
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
115+
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.NotFound);
116+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
113117
exception.Errors.ShouldHaveCount(1);
114-
exception.Errors[0].Status.Should().Be(((int)HttpStatusCode.NotFound).ToString());
118+
119+
ErrorObject error = exception.Errors.ElementAt(0);
120+
error.Status.Should().Be("404");
121+
error.Title.Should().Be("The requested resource does not exist.");
122+
error.Detail.Should().Be($"Resource of type 'countries' with ID '{unknownCountryId}' does not exist.");
115123

116124
headerInspector.ResponseHeaders.Should().NotContainKey(HeaderNames.ETag);
117125
}
@@ -188,6 +196,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
188196

189197
// Assert
190198
ApiException exception = (await action.Should().ThrowExactlyAsync<ApiException>()).Which;
199+
exception.Message.Should().Be("The server returned an unexpected status code and no error factory is registered for this code: 304");
191200
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.NotModified);
192201

193202
string[] eTagHeaderValues = headerInspector.ResponseHeaders.Should().ContainKey(HeaderNames.ETag).WhoseValue.ToArray();

test/OpenApiKiotaEndToEndTests/QueryStrings/FilterTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public async Task Cannot_use_empty_filter()
164164
// Assert
165165
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
166166
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.BadRequest);
167+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
167168
exception.Links.ShouldNotBeNull();
168169
exception.Links.Describedby.Should().Be("swagger/v1/swagger.json");
169170
exception.Errors.ShouldHaveCount(1);

test/OpenApiKiotaEndToEndTests/QueryStrings/PaginationTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public async Task Cannot_use_empty_page_size()
156156
// Assert
157157
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
158158
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.BadRequest);
159+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
159160
exception.Errors.ShouldHaveCount(1);
160161

161162
ErrorObject error = exception.Errors.ElementAt(0);
@@ -187,6 +188,7 @@ public async Task Cannot_use_empty_page_number()
187188
// Assert
188189
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
189190
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.BadRequest);
191+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
190192
exception.Errors.ShouldHaveCount(1);
191193

192194
ErrorObject error = exception.Errors.ElementAt(0);

test/OpenApiKiotaEndToEndTests/QueryStrings/SortTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public async Task Cannot_use_empty_sort()
155155
// Assert
156156
ErrorResponseDocument exception = (await action.Should().ThrowExactlyAsync<ErrorResponseDocument>()).Which;
157157
exception.ResponseStatusCode.Should().Be((int)HttpStatusCode.BadRequest);
158+
exception.Message.Should().Be($"Exception of type '{typeof(ErrorResponseDocument).FullName}' was thrown.");
158159
exception.Errors.ShouldHaveCount(1);
159160

160161
ErrorObject error = exception.Errors.ElementAt(0);

test/OpenApiNSwagEndToEndTests/Headers/ETagTests.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,26 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8585
public async Task Returns_no_ETag_for_failed_GET_request()
8686
{
8787
// Arrange
88+
string unknownCountryId = Unknown.StringId.For<Country, Guid>();
89+
8890
using HttpClient httpClient = _testContext.Factory.CreateDefaultClient(_logHttpMessageHandler);
8991
var apiClient = new HeadersClient(httpClient);
9092

9193
// Act
9294
Func<Task<ApiResponse<CountryPrimaryResponseDocument?>>> action = () =>
93-
ApiResponse.TranslateAsync(() => apiClient.GetCountryAsync(Unknown.StringId.For<Country, Guid>(), null, null));
95+
ApiResponse.TranslateAsync(() => apiClient.GetCountryAsync(unknownCountryId, null, null));
9496

9597
// Assert
9698
ApiException<ErrorResponseDocument> exception = (await action.Should().ThrowExactlyAsync<ApiException<ErrorResponseDocument>>()).Which;
9799
exception.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
100+
exception.Message.Should().Be("HTTP 404: The country does not exist.");
98101
exception.Headers.Should().NotContainKey(HeaderNames.ETag);
102+
exception.Result.Errors.ShouldHaveCount(1);
103+
104+
ErrorObject error = exception.Result.Errors.ElementAt(0);
105+
error.Status.Should().Be("404");
106+
error.Title.Should().Be("The requested resource does not exist.");
107+
error.Detail.Should().Be($"Resource of type 'countries' with ID '{unknownCountryId}' does not exist.");
99108
}
100109

101110
[Fact]

0 commit comments

Comments
 (0)