1
1
using FluentAssertions ;
2
- using FluentAssertions . Specialized ;
3
2
using JsonApiDotNetCore . OpenApi . Client . NSwag ;
4
- using Newtonsoft . Json ;
5
3
using OpenApiNSwagEndToEndTests . ModelStateValidation . GeneratedCode ;
6
4
using OpenApiTests ;
7
5
using OpenApiTests . ModelStateValidation ;
@@ -35,18 +33,19 @@ public async Task Cannot_violate_compare_constraint()
35
33
ModelStateValidationClient apiClient = new ( httpClient ) ;
36
34
37
35
// Act
38
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
36
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
39
37
{
40
38
Data = new SocialMediaAccountDataInPostRequest
41
39
{
42
40
Attributes = new SocialMediaAccountAttributesInPostRequest
43
41
{
44
42
FirstName = socialMediaAccount . FirstName ,
45
43
GivenName = "something else" ,
46
- LastName = ""
44
+ LastName = socialMediaAccount . LastName
47
45
}
48
46
}
49
- } ) ;
47
+ } ;
48
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
50
49
51
50
// Assert
52
51
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -65,22 +64,25 @@ public async Task Cannot_violate_compare_constraint()
65
64
public async Task Cannot_exceed_length_constraint ( string firstName )
66
65
{
67
66
// Arrange
67
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
68
+
68
69
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
69
70
ModelStateValidationClient apiClient = new ( httpClient ) ;
70
71
71
72
// Act
72
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
73
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
73
74
{
74
75
Data = new SocialMediaAccountDataInPostRequest
75
76
{
76
77
Attributes = new SocialMediaAccountAttributesInPostRequest
77
78
{
78
79
FirstName = firstName ,
79
80
GivenName = firstName ,
80
- LastName = ""
81
+ LastName = socialMediaAccount . LastName
81
82
}
82
83
}
83
- } ) ;
84
+ } ;
85
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
84
86
85
87
// Assert
86
88
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -99,21 +101,24 @@ public async Task Cannot_exceed_length_constraint(string firstName)
99
101
public async Task Cannot_exceed_string_length_constraint ( string userName )
100
102
{
101
103
// Arrange
104
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
105
+
102
106
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
103
107
ModelStateValidationClient apiClient = new ( httpClient ) ;
104
108
105
109
// Act
106
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
110
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
107
111
{
108
112
Data = new SocialMediaAccountDataInPostRequest
109
113
{
110
114
Attributes = new SocialMediaAccountAttributesInPostRequest
111
115
{
112
- LastName = "" ,
116
+ LastName = socialMediaAccount . LastName ,
113
117
UserName = userName ,
114
118
}
115
119
}
116
- } ) ;
120
+ } ;
121
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
117
122
118
123
// Assert
119
124
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -130,21 +135,24 @@ public async Task Cannot_exceed_string_length_constraint(string userName)
130
135
public async Task Cannot_violate_regular_expression_constraint ( )
131
136
{
132
137
// Arrange
138
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
139
+
133
140
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
134
141
ModelStateValidationClient apiClient = new ( httpClient ) ;
135
142
136
143
// Act
137
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
144
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
138
145
{
139
146
Data = new SocialMediaAccountDataInPostRequest
140
147
{
141
148
Attributes = new SocialMediaAccountAttributesInPostRequest
142
149
{
143
- LastName = "" ,
150
+ LastName = socialMediaAccount . LastName ,
144
151
UserName = "aB1" ,
145
152
}
146
153
}
147
- } ) ;
154
+ } ;
155
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
148
156
149
157
// Assert
150
158
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -158,24 +166,27 @@ public async Task Cannot_violate_regular_expression_constraint()
158
166
}
159
167
160
168
[ Fact ]
161
- public async Task Cannot_use_invalid_credit_card ( )
169
+ public async Task Cannot_use_invalid_credit_card_number ( )
162
170
{
163
171
// Arrange
172
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
173
+
164
174
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
165
175
ModelStateValidationClient apiClient = new ( httpClient ) ;
166
176
167
177
// Act
168
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
178
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
169
179
{
170
180
Data = new SocialMediaAccountDataInPostRequest
171
181
{
172
182
Attributes = new SocialMediaAccountAttributesInPostRequest
173
183
{
174
- LastName = "" ,
184
+ LastName = socialMediaAccount . LastName ,
175
185
CreditCard = "123-456" ,
176
186
}
177
187
}
178
- } ) ;
188
+ } ;
189
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
179
190
180
191
// Assert
181
192
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -192,21 +203,24 @@ public async Task Cannot_use_invalid_credit_card()
192
203
public async Task Cannot_use_invalid_email ( )
193
204
{
194
205
// Arrange
206
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
207
+
195
208
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
196
209
ModelStateValidationClient apiClient = new ( httpClient ) ;
197
210
198
211
// Act
199
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
212
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
200
213
{
201
214
Data = new SocialMediaAccountDataInPostRequest
202
215
{
203
216
Attributes = new SocialMediaAccountAttributesInPostRequest
204
217
{
205
- LastName = "" ,
218
+ LastName = socialMediaAccount . LastName ,
206
219
Email = "abc" ,
207
220
}
208
221
}
209
- } ) ;
222
+ } ;
223
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
210
224
211
225
// Assert
212
226
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -227,21 +241,24 @@ public async Task Cannot_use_invalid_email()
227
241
public async Task Cannot_use_double_outside_of_valid_range ( int age )
228
242
{
229
243
// Arrange
244
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
245
+
230
246
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
231
247
ModelStateValidationClient apiClient = new ( httpClient ) ;
232
248
233
249
// Act
234
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
250
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
235
251
{
236
252
Data = new SocialMediaAccountDataInPostRequest
237
253
{
238
254
Attributes = new SocialMediaAccountAttributesInPostRequest
239
255
{
240
- LastName = "" ,
256
+ LastName = socialMediaAccount . LastName ,
241
257
Age = age ,
242
258
}
243
259
}
244
- } ) ;
260
+ } ;
261
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
245
262
246
263
// Assert
247
264
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -255,24 +272,27 @@ public async Task Cannot_use_double_outside_of_valid_range(int age)
255
272
}
256
273
257
274
[ Fact ]
258
- public async Task Cannot_use_invalid_url ( )
275
+ public async Task Cannot_use_relative_url ( )
259
276
{
260
277
// Arrange
278
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
279
+
261
280
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
262
281
ModelStateValidationClient apiClient = new ( httpClient ) ;
263
282
264
283
// Act
265
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
284
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
266
285
{
267
286
Data = new SocialMediaAccountDataInPostRequest
268
287
{
269
288
Attributes = new SocialMediaAccountAttributesInPostRequest
270
289
{
271
- LastName = "" ,
290
+ LastName = socialMediaAccount . LastName ,
272
291
BackgroundPicture = new Uri ( "/justapath" , UriKind . Relative ) ,
273
292
}
274
293
}
275
- } ) ;
294
+ } ;
295
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
276
296
277
297
// Assert
278
298
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -291,21 +311,24 @@ public async Task Cannot_use_invalid_url()
291
311
public async Task Cannot_exceed_collection_length_constraint ( int length )
292
312
{
293
313
// Arrange
314
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
315
+
294
316
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
295
317
ModelStateValidationClient apiClient = new ( httpClient ) ;
296
318
297
319
// Act
298
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
320
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
299
321
{
300
322
Data = new SocialMediaAccountDataInPostRequest
301
323
{
302
324
Attributes = new SocialMediaAccountAttributesInPostRequest
303
325
{
304
- LastName = "" ,
305
- Tags = Enumerable . Repeat ( "" , length ) . ToArray ( ) ,
326
+ LastName = socialMediaAccount . LastName ,
327
+ Tags = Enumerable . Repeat ( "- " , length ) . ToArray ( ) ,
306
328
}
307
329
}
308
- } ) ;
330
+ } ;
331
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
309
332
310
333
// Assert
311
334
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -322,21 +345,24 @@ public async Task Cannot_exceed_collection_length_constraint(int length)
322
345
public async Task Cannot_use_non_allowed_value ( )
323
346
{
324
347
// Arrange
348
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
349
+
325
350
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
326
351
ModelStateValidationClient apiClient = new ( httpClient ) ;
327
352
328
353
// Act
329
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
354
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
330
355
{
331
356
Data = new SocialMediaAccountDataInPostRequest
332
357
{
333
358
Attributes = new SocialMediaAccountAttributesInPostRequest
334
359
{
335
- LastName = "" ,
360
+ LastName = socialMediaAccount . LastName ,
336
361
CountryCode = "XX"
337
362
}
338
363
}
339
- } ) ;
364
+ } ;
365
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
340
366
341
367
// Assert
342
368
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -353,21 +379,24 @@ public async Task Cannot_use_non_allowed_value()
353
379
public async Task Cannot_use_denied_value ( )
354
380
{
355
381
// Arrange
382
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
383
+
356
384
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
357
385
ModelStateValidationClient apiClient = new ( httpClient ) ;
358
386
359
387
// Act
360
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
388
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
361
389
{
362
390
Data = new SocialMediaAccountDataInPostRequest
363
391
{
364
392
Attributes = new SocialMediaAccountAttributesInPostRequest
365
393
{
366
- LastName = "" ,
394
+ LastName = socialMediaAccount . LastName ,
367
395
Planet = "pluto"
368
396
}
369
397
}
370
- } ) ;
398
+ } ;
399
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
371
400
372
401
// Assert
373
402
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -384,21 +413,24 @@ public async Task Cannot_use_denied_value()
384
413
public async Task Cannot_use_TimeSpan_outside_of_valid_range ( )
385
414
{
386
415
// Arrange
416
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
417
+
387
418
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
388
419
ModelStateValidationClient apiClient = new ( httpClient ) ;
389
420
390
421
// Act
391
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
422
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
392
423
{
393
424
Data = new SocialMediaAccountDataInPostRequest
394
425
{
395
426
Attributes = new SocialMediaAccountAttributesInPostRequest
396
427
{
397
- LastName = "" ,
428
+ LastName = socialMediaAccount . LastName ,
398
429
NextRevalidation = "00:00:01" ,
399
430
}
400
431
}
401
- } ) ;
432
+ } ;
433
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
402
434
403
435
// Assert
404
436
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -415,21 +447,24 @@ public async Task Cannot_use_TimeSpan_outside_of_valid_range()
415
447
public async Task Cannot_use_invalid_TimeOnly ( )
416
448
{
417
449
// Arrange
450
+ SocialMediaAccount socialMediaAccount = _fakers . SocialMediaAccount . Generate ( ) ;
451
+
418
452
using HttpClient httpClient = _testContext . Factory . CreateDefaultClient ( _logHttpMessageHandler ) ;
419
453
ModelStateValidationClient apiClient = new ( httpClient ) ;
420
454
421
455
// Act
422
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
456
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
423
457
{
424
458
Data = new SocialMediaAccountDataInPostRequest
425
459
{
426
460
Attributes = new SocialMediaAccountAttributesInPostRequest
427
461
{
428
- LastName = "" ,
462
+ LastName = socialMediaAccount . LastName ,
429
463
ValidatedAtTime = TimeSpan . FromSeconds ( - 1 ) ,
430
464
}
431
465
}
432
- } ) ;
466
+ } ;
467
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
433
468
434
469
// Assert
435
470
ErrorResponseDocument document = ( await action . Should ( ) . ThrowExactlyAsync < ApiException < ErrorResponseDocument > > ( ) ) . Which . Result ;
@@ -452,7 +487,7 @@ public async Task Can_create_resource_with_valid_properties()
452
487
ModelStateValidationClient apiClient = new ( httpClient ) ;
453
488
454
489
// Act
455
- Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( new SocialMediaAccountPostRequestDocument
490
+ SocialMediaAccountPostRequestDocument requestBody = new ( )
456
491
{
457
492
Data = new SocialMediaAccountDataInPostRequest
458
493
{
@@ -476,7 +511,8 @@ public async Task Can_create_resource_with_valid_properties()
476
511
ValidatedAtTime = socialMediaAccount . ValidatedAtTime ! . Value . ToTimeSpan ( )
477
512
}
478
513
}
479
- } ) ;
514
+ } ;
515
+ Func < Task < SocialMediaAccountPrimaryResponseDocument > > action = ( ) => apiClient . PostSocialMediaAccountAsync ( requestBody ) ;
480
516
481
517
// Assert
482
518
await action . Should ( ) . NotThrowAsync ( ) ;
0 commit comments