@@ -29,6 +29,24 @@ public async Task ReadFormAsync_0ContentLength_ReturnsEmptyForm()
2929 Assert . Same ( FormCollection . Empty , formCollection ) ;
3030 }
3131
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+
3250 [ Theory ]
3351 [ InlineData ( true ) ]
3452 [ InlineData ( false ) ]
@@ -391,7 +409,7 @@ public async Task ReadFormAsync_ValueCountLimitExceeded_Throw(bool bufferRequest
391409 IFormFeature formFeature = new FormFeature ( context . Request , new FormOptions ( ) { BufferBody = bufferRequest , ValueCountLimit = 2 } ) ;
392410 context . Features . Set < IFormFeature > ( formFeature ) ;
393411
394- var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
412+ var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
395413 Assert . Equal ( "Form value count limit 2 exceeded." , exception . Message ) ;
396414 }
397415
@@ -416,7 +434,7 @@ public async Task ReadFormAsync_ValueCountLimitExceededWithFiles_Throw(bool buff
416434 IFormFeature formFeature = new FormFeature ( context . Request , new FormOptions ( ) { BufferBody = bufferRequest , ValueCountLimit = 2 } ) ;
417435 context . Features . Set < IFormFeature > ( formFeature ) ;
418436
419- var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
437+ var exception = await Assert . ThrowsAsync < InvalidDataException > ( ( ) => context . Request . ReadFormAsync ( ) ) ;
420438 Assert . Equal ( "Form value count limit 2 exceeded." , exception . Message ) ;
421439 }
422440
0 commit comments