@@ -13,7 +13,7 @@ namespace WebApiClientCore.Test.Attributes.ParameterAttributes
1313 public class JsonContentAttributeTest
1414 {
1515 [ Fact ]
16- public async Task BeforeRequestAsyncTest ( )
16+ public async Task Utf16ChunkedTest ( )
1717 {
1818 var apiAction = new DefaultApiActionDescriptor ( typeof ( IMyApi ) . GetMethod ( "PostAsync" ) ! ) ;
1919 var context = new TestRequestContext ( apiAction , new
@@ -25,9 +25,32 @@ public async Task BeforeRequestAsyncTest()
2525 context . HttpContext . RequestMessage . RequestUri = new Uri ( "http://www.webapi.com/" ) ;
2626 context . HttpContext . RequestMessage . Method = HttpMethod . Post ;
2727
28- var attr = new JsonContentAttribute ( ) { CharSet = "utf-16" } ;
28+ var attr = new JsonContentAttribute ( ) { CharSet = "utf-16" , AllowChunked = true } ;
2929 await attr . OnRequestAsync ( new ApiParameterContext ( context , 0 ) ) ;
30+ var body = await context . HttpContext . RequestMessage . Content ! . ReadAsUtf8ByteArrayAsync ( ) ;
3031
32+ var options = context . HttpContext . HttpApiOptions . JsonSerializeOptions ;
33+ using var buffer = new RecyclableBufferWriter < byte > ( ) ;
34+ JsonBufferSerializer . Serialize ( buffer , context . Arguments [ 0 ] , options ) ;
35+ var target = buffer . WrittenSpan . ToArray ( ) ;
36+ Assert . True ( body . SequenceEqual ( target ) ) ;
37+ }
38+
39+ [ Fact ]
40+ public async Task Utf8UnChunkedTest ( )
41+ {
42+ var apiAction = new DefaultApiActionDescriptor ( typeof ( IMyApi ) . GetMethod ( "PostAsync" ) ! ) ;
43+ var context = new TestRequestContext ( apiAction , new
44+ {
45+ name = "laojiu" ,
46+ birthDay = DateTime . Parse ( "2010-10-10" )
47+ } ) ;
48+
49+ context . HttpContext . RequestMessage . RequestUri = new Uri ( "http://www.webapi.com/" ) ;
50+ context . HttpContext . RequestMessage . Method = HttpMethod . Post ;
51+
52+ var attr = new JsonContentAttribute ( ) { CharSet = "utf-8" , AllowChunked = false } ;
53+ await attr . OnRequestAsync ( new ApiParameterContext ( context , 0 ) ) ;
3154 var body = await context . HttpContext . RequestMessage . Content ! . ReadAsUtf8ByteArrayAsync ( ) ;
3255
3356 var options = context . HttpContext . HttpApiOptions . JsonSerializeOptions ;
0 commit comments