Skip to content

Commit 4488a21

Browse files
committed
Update EndToEndTests to use nullability defaults from NuGet package
1 parent 54c31ed commit 4488a21

21 files changed

+184
-99
lines changed

test/OpenApiKiotaEndToEndTests/AtomicOperations/AtomicCreateResourceTests.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public async Task Can_create_resource_with_attributes()
6969
response.AtomicResults.ShouldHaveCount(1);
7070
TeacherDataInResponse teacherDataInResponse = response.AtomicResults.ElementAt(0).Data.Should().BeOfType<TeacherDataInResponse>().Which;
7171

72-
teacherDataInResponse.Attributes!.Name.Should().Be(newTeacher.Name);
72+
teacherDataInResponse.Attributes.ShouldNotBeNull();
73+
teacherDataInResponse.Attributes.Name.Should().Be(newTeacher.Name);
7374
teacherDataInResponse.Attributes.EmailAddress.Should().Be(newTeacher.EmailAddress);
7475

7576
long newTeacherId = long.Parse(teacherDataInResponse.Id!);
@@ -147,7 +148,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
147148
response.AtomicResults.ShouldHaveCount(1);
148149
EnrollmentDataInResponse enrollmentDataInResponse = response.AtomicResults.ElementAt(0).Data.Should().BeOfType<EnrollmentDataInResponse>().Which;
149150

150-
enrollmentDataInResponse.Attributes!.EnrolledAt.Should().Be((Date)newEnrollment.EnrolledAt);
151+
enrollmentDataInResponse.Attributes.ShouldNotBeNull();
152+
enrollmentDataInResponse.Attributes.EnrolledAt.Should().Be((Date)newEnrollment.EnrolledAt);
151153
enrollmentDataInResponse.Attributes.GraduatedAt.Should().BeNull();
152154
enrollmentDataInResponse.Attributes.HasGraduated.Should().BeFalse();
153155

test/OpenApiKiotaEndToEndTests/AtomicOperations/AtomicLocalIdTests.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,23 @@ public async Task Can_use_local_IDs()
180180
response.AtomicResults.ShouldHaveCount(7);
181181

182182
TeacherDataInResponse teacherInResponse = response.AtomicResults.ElementAt(0).Data.Should().BeOfType<TeacherDataInResponse>().Which;
183-
teacherInResponse.Attributes!.Name.Should().Be(newTeacher.Name);
183+
teacherInResponse.Attributes.ShouldNotBeNull();
184+
teacherInResponse.Attributes.Name.Should().Be(newTeacher.Name);
184185
teacherInResponse.Attributes.EmailAddress.Should().Be(newTeacher.EmailAddress);
185186
long newTeacherId = long.Parse(teacherInResponse.Id!);
186187

187188
response.AtomicResults.ElementAt(1).Data.Should().BeNull();
188189
response.AtomicResults.ElementAt(2).Data.Should().BeNull();
189190

190191
StudentDataInResponse studentInResponse = response.AtomicResults.ElementAt(3).Data.Should().BeOfType<StudentDataInResponse>().Which;
191-
studentInResponse.Attributes!.Name.Should().Be(newStudent.Name);
192+
studentInResponse.Attributes.ShouldNotBeNull();
193+
studentInResponse.Attributes.Name.Should().Be(newStudent.Name);
192194
studentInResponse.Attributes.EmailAddress.Should().Be(newStudent.EmailAddress);
193195
long newStudentId = long.Parse(studentInResponse.Id!);
194196

195197
EnrollmentDataInResponse enrollmentInResponse = response.AtomicResults.ElementAt(4).Data.Should().BeOfType<EnrollmentDataInResponse>().Which;
196-
enrollmentInResponse.Attributes!.EnrolledAt.Should().Be((Date)newEnrolledAt);
198+
enrollmentInResponse.Attributes.ShouldNotBeNull();
199+
enrollmentInResponse.Attributes.EnrolledAt.Should().Be((Date)newEnrolledAt);
197200
long newEnrollmentId = long.Parse(enrollmentInResponse.Id!);
198201

199202
response.AtomicResults.ElementAt(5).Data.Should().BeNull();

test/OpenApiKiotaEndToEndTests/AtomicOperations/AtomicUpdateResourceTests.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8585
StudentDataInResponse studentDataInResponse = response.AtomicResults.ElementAt(0).Data.Should().BeOfType<StudentDataInResponse>().Which;
8686

8787
studentDataInResponse.Id.Should().Be(existingStudent.StringId);
88-
studentDataInResponse.Attributes!.Name.Should().Be(newName);
88+
studentDataInResponse.Attributes.ShouldNotBeNull();
89+
studentDataInResponse.Attributes.Name.Should().Be(newName);
8990
studentDataInResponse.Attributes.EmailAddress.Should().Be(newEmailAddress);
9091

9192
await _testContext.RunOnDatabaseAsync(async dbContext =>
@@ -148,7 +149,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
148149
StudentDataInResponse studentDataInResponse = response.AtomicResults.ElementAt(0).Data.Should().BeOfType<StudentDataInResponse>().Which;
149150

150151
studentDataInResponse.Id.Should().Be(existingStudent.StringId);
151-
studentDataInResponse.Attributes!.Name.Should().Be(existingStudent.Name);
152+
studentDataInResponse.Attributes.ShouldNotBeNull();
153+
studentDataInResponse.Attributes.Name.Should().Be(existingStudent.Name);
152154
studentDataInResponse.Attributes.EmailAddress.Should().Be(newEmailAddress);
153155

154156
await _testContext.RunOnDatabaseAsync(async dbContext =>
@@ -230,7 +232,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
230232
EnrollmentDataInResponse enrollmentDataInResponse = response.AtomicResults.ElementAt(0).Data.Should().BeOfType<EnrollmentDataInResponse>().Which;
231233

232234
enrollmentDataInResponse.Id.Should().Be(existingEnrollment.StringId);
233-
enrollmentDataInResponse.Attributes!.EnrolledAt.Should().Be((Date)newEnrolledAt);
235+
enrollmentDataInResponse.Attributes.ShouldNotBeNull();
236+
enrollmentDataInResponse.Attributes.EnrolledAt.Should().Be((Date)newEnrolledAt);
234237
enrollmentDataInResponse.Attributes.GraduatedAt.Should().Be((Date)existingEnrollment.GraduatedAt!.Value);
235238
enrollmentDataInResponse.Attributes.HasGraduated.Should().Be(existingEnrollment.HasGraduated);
236239

test/OpenApiKiotaEndToEndTests/QueryStrings/FilterTests.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
5757
response.ShouldNotBeNull();
5858
response.Data.ShouldHaveCount(1);
5959
response.Data.ElementAt(0).Id.Should().Be(nodes[1].StringId);
60-
response.Data.ElementAt(0).Attributes!.Name.Should().Be(nodes[1].Name);
61-
response.Data.ElementAt(0).Attributes!.Comment.Should().Be(nodes[1].Comment);
60+
61+
response.Data.ElementAt(0).Attributes.ShouldNotBeNull().With(attributes =>
62+
{
63+
attributes.Name.Should().Be(nodes[1].Name);
64+
attributes.Comment.Should().Be(nodes[1].Comment);
65+
});
66+
6267
response.Meta.ShouldNotBeNull();
6368
response.Meta.AdditionalData.ShouldContainKey("total").With(total => total.Should().Be(1));
6469
}
@@ -97,8 +102,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
97102
response.ShouldNotBeNull();
98103
response.Data.ShouldHaveCount(1);
99104
response.Data.ElementAt(0).Id.Should().Be(node.Children.ElementAt(1).StringId);
100-
response.Data.ElementAt(0).Attributes!.Name.Should().Be(node.Children.ElementAt(1).Name);
101-
response.Data.ElementAt(0).Attributes!.Comment.Should().Be(node.Children.ElementAt(1).Comment);
105+
106+
response.Data.ElementAt(0).Attributes.ShouldNotBeNull().With(attributes =>
107+
{
108+
attributes.Name.Should().Be(node.Children.ElementAt(1).Name);
109+
attributes.Comment.Should().Be(node.Children.ElementAt(1).Comment);
110+
});
111+
102112
response.Meta.ShouldNotBeNull();
103113
response.Meta.AdditionalData.ShouldContainKey("total").With(total => total.Should().Be(1));
104114
}

test/OpenApiKiotaEndToEndTests/QueryStrings/SparseFieldSetTests.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
5555
response.ShouldNotBeNull();
5656
response.Data.ShouldHaveCount(1);
5757
response.Data.ElementAt(0).Id.Should().Be(node.StringId);
58-
response.Data.ElementAt(0).Attributes.ShouldNotBeNull();
59-
response.Data.ElementAt(0).Attributes!.Name.Should().Be(node.Name);
60-
response.Data.ElementAt(0).Attributes!.Comment.Should().BeNull();
58+
59+
response.Data.ElementAt(0).Attributes.ShouldNotBeNull().With(attributes =>
60+
{
61+
attributes.Name.Should().Be(node.Name);
62+
attributes.Comment.Should().BeNull();
63+
});
64+
6165
response.Data.ElementAt(0).Relationships.Should().BeNull();
6266
}
6367
}
@@ -131,12 +135,18 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
131135
response.ShouldNotBeNull();
132136
response.Data.ShouldHaveCount(1);
133137
response.Data.ElementAt(0).Id.Should().Be(node.Children.ElementAt(0).StringId);
134-
response.Data.ElementAt(0).Attributes.ShouldNotBeNull();
135-
response.Data.ElementAt(0).Attributes!.Name.Should().BeNull();
136-
response.Data.ElementAt(0).Attributes!.Comment.Should().Be(node.Children.ElementAt(0).Comment);
137-
response.Data.ElementAt(0).Relationships.ShouldNotBeNull();
138-
response.Data.ElementAt(0).Relationships!.Parent.Should().BeNull();
139-
response.Data.ElementAt(0).Relationships!.Children.ShouldNotBeNull();
138+
139+
response.Data.ElementAt(0).Attributes.ShouldNotBeNull().With(attributes =>
140+
{
141+
attributes.Name.Should().BeNull();
142+
attributes.Comment.Should().Be(node.Children.ElementAt(0).Comment);
143+
});
144+
145+
response.Data.ElementAt(0).Relationships.ShouldNotBeNull().With(relationships =>
146+
{
147+
relationships.Parent.Should().BeNull();
148+
relationships.Children.ShouldNotBeNull();
149+
});
140150
}
141151
}
142152

test/OpenApiNSwagEndToEndTests/AtomicOperations/AtomicCreateResourceTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public async Task Can_create_resource_with_attributes()
6666
response.Atomic_results.ShouldHaveCount(1);
6767
TeacherDataInResponse teacherDataInResponse = response.Atomic_results.ElementAt(0).Data.Should().BeOfType<TeacherDataInResponse>().Which;
6868

69+
teacherDataInResponse.Attributes.ShouldNotBeNull();
6970
teacherDataInResponse.Attributes.Name.Should().Be(newTeacher.Name);
7071
teacherDataInResponse.Attributes.EmailAddress.Should().Be(newTeacher.EmailAddress);
7172

@@ -140,6 +141,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
140141
response.Atomic_results.ShouldHaveCount(1);
141142
EnrollmentDataInResponse enrollmentDataInResponse = response.Atomic_results.ElementAt(0).Data.Should().BeOfType<EnrollmentDataInResponse>().Which;
142143

144+
enrollmentDataInResponse.Attributes.ShouldNotBeNull();
143145
enrollmentDataInResponse.Attributes.EnrolledAt.Should().Be(newEnrollment.EnrolledAt.ToDateTime(TimeOnly.MinValue));
144146
enrollmentDataInResponse.Attributes.GraduatedAt.Should().BeNull();
145147
enrollmentDataInResponse.Attributes.HasGraduated.Should().BeFalse();

test/OpenApiNSwagEndToEndTests/AtomicOperations/AtomicLocalIdTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public async Task Can_use_local_IDs()
158158
response.Atomic_results.ShouldHaveCount(7);
159159

160160
TeacherDataInResponse teacherInResponse = response.Atomic_results.ElementAt(0).Data.Should().BeOfType<TeacherDataInResponse>().Which;
161+
teacherInResponse.Attributes.ShouldNotBeNull();
161162
teacherInResponse.Attributes.Name.Should().Be(newTeacher.Name);
162163
teacherInResponse.Attributes.EmailAddress.Should().Be(newTeacher.EmailAddress);
163164
long newTeacherId = long.Parse(teacherInResponse.Id);
@@ -166,11 +167,13 @@ public async Task Can_use_local_IDs()
166167
response.Atomic_results.ElementAt(2).Data.Should().BeNull();
167168

168169
StudentDataInResponse studentInResponse = response.Atomic_results.ElementAt(3).Data.Should().BeOfType<StudentDataInResponse>().Which;
170+
studentInResponse.Attributes.ShouldNotBeNull();
169171
studentInResponse.Attributes.Name.Should().Be(newStudent.Name);
170172
studentInResponse.Attributes.EmailAddress.Should().Be(newStudent.EmailAddress);
171173
long newStudentId = long.Parse(studentInResponse.Id);
172174

173175
EnrollmentDataInResponse enrollmentInResponse = response.Atomic_results.ElementAt(4).Data.Should().BeOfType<EnrollmentDataInResponse>().Which;
176+
enrollmentInResponse.Attributes.ShouldNotBeNull();
174177
enrollmentInResponse.Attributes.EnrolledAt.Should().Be(newEnrolledAt.ToDateTime(TimeOnly.MinValue));
175178
long newEnrollmentId = long.Parse(enrollmentInResponse.Id);
176179

test/OpenApiNSwagEndToEndTests/AtomicOperations/AtomicUpdateResourceTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8181
StudentDataInResponse studentDataInResponse = response.Atomic_results.ElementAt(0).Data.Should().BeOfType<StudentDataInResponse>().Which;
8282

8383
studentDataInResponse.Id.Should().Be(existingStudent.StringId);
84+
studentDataInResponse.Attributes.ShouldNotBeNull();
8485
studentDataInResponse.Attributes.Name.Should().Be(newName);
8586
studentDataInResponse.Attributes.EmailAddress.Should().Be(newEmailAddress);
8687

@@ -141,6 +142,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
141142
StudentDataInResponse studentDataInResponse = response.Atomic_results.ElementAt(0).Data.Should().BeOfType<StudentDataInResponse>().Which;
142143

143144
studentDataInResponse.Id.Should().Be(existingStudent.StringId);
145+
studentDataInResponse.Attributes.ShouldNotBeNull();
144146
studentDataInResponse.Attributes.Name.Should().Be(existingStudent.Name);
145147
studentDataInResponse.Attributes.EmailAddress.Should().Be(newEmailAddress);
146148

@@ -219,6 +221,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
219221
EnrollmentDataInResponse enrollmentDataInResponse = response.Atomic_results.ElementAt(0).Data.Should().BeOfType<EnrollmentDataInResponse>().Which;
220222

221223
enrollmentDataInResponse.Id.Should().Be(existingEnrollment.StringId);
224+
enrollmentDataInResponse.Attributes.ShouldNotBeNull();
222225
enrollmentDataInResponse.Attributes.EnrolledAt.Should().Be(newEnrolledAt.ToDateTime(TimeOnly.MinValue));
223226
enrollmentDataInResponse.Attributes.GraduatedAt.Should().Be(existingEnrollment.GraduatedAt!.Value.ToDateTime(TimeOnly.MinValue));
224227
enrollmentDataInResponse.Attributes.HasGraduated.Should().Be(existingEnrollment.HasGraduated);

test/OpenApiNSwagEndToEndTests/Headers/ETagTests.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
4242
var apiClient = new HeadersClient(httpClient);
4343

4444
// Act
45-
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryCollectionAsync(null, null));
45+
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryCollectionAsync());
4646

4747
// Assert
4848
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
@@ -69,8 +69,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
6969
var apiClient = new HeadersClient(httpClient);
7070

7171
// Act
72-
ApiResponse<CountryCollectionResponseDocument?> response =
73-
await ApiResponse.TranslateAsync(async () => await apiClient.GetCountryCollectionAsync(null, null));
72+
ApiResponse<CountryCollectionResponseDocument?> response = await ApiResponse.TranslateAsync(async () => await apiClient.GetCountryCollectionAsync());
7473

7574
// Assert
7675
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
@@ -92,7 +91,7 @@ public async Task Returns_no_ETag_for_failed_GET_request()
9291
var apiClient = new HeadersClient(httpClient);
9392

9493
// Act
95-
Func<Task> action = async () => await ApiResponse.TranslateAsync(async () => await apiClient.GetCountryAsync(unknownCountryId, null, null));
94+
Func<Task> action = async () => await ApiResponse.TranslateAsync(async () => await apiClient.GetCountryAsync(unknownCountryId));
9695

9796
// Assert
9897
ApiException<ErrorResponseDocument> exception = (await action.Should().ThrowExactlyAsync<ApiException<ErrorResponseDocument>>()).Which;
@@ -129,8 +128,7 @@ public async Task Returns_no_ETag_for_POST_request()
129128
};
130129

131130
// Act
132-
ApiResponse<CountryPrimaryResponseDocument?> response =
133-
await ApiResponse.TranslateAsync(async () => await apiClient.PostCountryAsync(null, requestBody));
131+
ApiResponse<CountryPrimaryResponseDocument?> response = await ApiResponse.TranslateAsync(async () => await apiClient.PostCountryAsync(requestBody));
134132

135133
// Assert
136134
response.StatusCode.Should().Be((int)HttpStatusCode.Created);
@@ -156,8 +154,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
156154
using HttpClient httpClient = _testContext.Factory.CreateDefaultClient(_logHttpMessageHandler);
157155
var apiClient = new HeadersClient(httpClient);
158156

159-
ApiResponse<CountryCollectionResponseDocument?> response1 =
160-
await ApiResponse.TranslateAsync(async () => await apiClient.GetCountryCollectionAsync(null, null));
157+
ApiResponse<CountryCollectionResponseDocument?> response1 = await ApiResponse.TranslateAsync(async () => await apiClient.GetCountryCollectionAsync());
161158

162159
string responseETag = response1.Headers[HeaderNames.ETag].Single();
163160

test/OpenApiNSwagEndToEndTests/Headers/HeaderTests.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public async Task Returns_Location_for_post_resource_request()
4747
};
4848

4949
// Act
50-
ApiResponse<CountryPrimaryResponseDocument?> response =
51-
await ApiResponse.TranslateAsync(async () => await apiClient.PostCountryAsync(null, requestBody));
50+
ApiResponse<CountryPrimaryResponseDocument?> response = await ApiResponse.TranslateAsync(async () => await apiClient.PostCountryAsync(requestBody));
5251

5352
// Assert
5453
response.StatusCode.Should().Be((int)HttpStatusCode.Created);
@@ -77,7 +76,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
7776
var apiClient = new HeadersClient(httpClient);
7877

7978
// Act
80-
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryCollectionAsync(null, null));
79+
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryCollectionAsync());
8180

8281
// Assert
8382
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
@@ -103,7 +102,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
103102
var apiClient = new HeadersClient(httpClient);
104103

105104
// Act
106-
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryAsync(existingCountry.Id, null, null));
105+
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryAsync(existingCountry.Id));
107106

108107
// Assert
109108
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
@@ -130,7 +129,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
130129
var apiClient = new HeadersClient(httpClient);
131130

132131
// Act
133-
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryLanguagesAsync(existingCountry.Id, null, null));
132+
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryLanguagesAsync(existingCountry.Id));
134133

135134
// Assert
136135
response.StatusCode.Should().Be((int)HttpStatusCode.OK);
@@ -157,8 +156,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
157156
var apiClient = new HeadersClient(httpClient);
158157

159158
// Act
160-
ApiResponse response =
161-
await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryLanguagesRelationshipAsync(existingCountry.Id, null, null));
159+
ApiResponse response = await ApiResponse.TranslateAsync(async () => await apiClient.HeadCountryLanguagesRelationshipAsync(existingCountry.Id));
162160

163161
// Assert
164162
response.StatusCode.Should().Be((int)HttpStatusCode.OK);

test/OpenApiNSwagEndToEndTests/Links/AlternateOpenApiRouteTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
4343
});
4444

4545
// Act
46-
ExcursionPrimaryResponseDocument response = await apiClient.GetExcursionAsync(excursion.StringId!, null, null);
46+
ExcursionPrimaryResponseDocument response = await apiClient.GetExcursionAsync(excursion.StringId!);
4747

4848
// Assert
4949
response.Links.Describedby.Should().Be("/api-docs/v1/swagger.yaml");

0 commit comments

Comments
 (0)