@@ -29,6 +29,24 @@ public async Task ReadFormAsync_0ContentLength_ReturnsEmptyForm()
29
29
Assert . Same ( FormCollection . Empty , formCollection ) ;
30
30
}
31
31
32
+ [ Fact ]
33
+ public async Task FormFeatureReadsOptionsFromDefaultHttpContext ( )
34
+ {
35
+ var context = new DefaultHttpContext ( ) ;
36
+ context . Request . ContentType = "application/x-www-form-urlencoded; charset=utf-8" ;
37
+ context . FormOptions = new FormOptions
38
+ {
39
+ ValueCountLimit = 1
40
+ } ;
41
+
42
+ var formContent = Encoding . UTF8 . GetBytes ( "foo=bar&baz=2" ) ;
43
+ context . Request . Body = new NonSeekableReadStream ( formContent ) ;
44
+
45
+ var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
46
+
47
+ Assert . Equal ( "Form value count limit 1 exceeded." , exception . Message ) ;
48
+ }
49
+
32
50
[ Theory ]
33
51
[ InlineData ( true ) ]
34
52
[ InlineData ( false ) ]
@@ -391,7 +409,7 @@ public async Task ReadFormAsync_ValueCountLimitExceeded_Throw(bool bufferRequest
391
409
IFormFeature formFeature = new FormFeature ( context . Request , new FormOptions ( ) { BufferBody = bufferRequest , ValueCountLimit = 2 } ) ;
392
410
context . Features . Set < IFormFeature > ( formFeature ) ;
393
411
394
- var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
412
+ var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
395
413
Assert . Equal ( "Form value count limit 2 exceeded." , exception . Message ) ;
396
414
}
397
415
@@ -416,7 +434,7 @@ public async Task ReadFormAsync_ValueCountLimitExceededWithFiles_Throw(bool buff
416
434
IFormFeature formFeature = new FormFeature ( context . Request , new FormOptions ( ) { BufferBody = bufferRequest , ValueCountLimit = 2 } ) ;
417
435
context . Features . Set < IFormFeature > ( formFeature ) ;
418
436
419
- var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
437
+ var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
420
438
Assert . Equal ( "Form value count limit 2 exceeded." , exception . Message ) ;
421
439
}
422
440
0 commit comments