@@ -20,7 +20,7 @@ public TestResponseHasCorrectEncoding()
2020 dc . AddFile ( "endpoint1\\ myfile.txt" , "æøå" ) ;
2121
2222 var endpoint2 = DataUtils . CreateSimpleEndpoint ( "endpoint2" , "myfile.txt" , "/endpoint2" ) ;
23- endpoint2 . responses [ 0 ] . charset = "utf-8 " ;
23+ endpoint2 . responses [ 0 ] . charset = "latin1 " ;
2424 dc . AddFile ( "endpoint2\\ endpoint.json" , JsonConvert . SerializeObject ( endpoint2 ) ) ;
2525 dc . AddFile ( "endpoint2\\ myfile.txt" , "æøå" ) ;
2626 var tests = new List < JSONTest > ( new [ ] {
@@ -43,39 +43,43 @@ public override EndpointCollectionProvider GetEndpointCollectionProvider()
4343 }
4444
4545 [ Fact ]
46- async public Task ResponseHasLatin1EncodingIfNotConfigured ( )
46+ async public Task ResponseHasUtf8EncodingIfNotConfigured ( )
4747 {
4848 var response = await client . GetAsync ( "/endpoint1" ) ;
4949 var bytes = await response . Content . ReadAsByteArrayAsync ( ) ;
50- var str = Encoding . GetEncoding ( "ISO-8859-1" ) . GetString ( bytes ) ;
51- Assert . Equal ( "æøå" , str ) ;
50+ Assert . Equal ( "æøå" , DecodeUtf8 ( bytes ) ) ;
51+ Assert . NotEqual ( "æøå" , DecodeLatin1 ( bytes ) ) ;
52+ }
5253
53- var utf8string = Encoding . UTF8 . GetString ( bytes ) ;
54- Assert . NotEqual ( "æøå" , utf8string ) ;
54+ private string DecodeLatin1 ( byte [ ] bytes )
55+ {
56+ return Encoding . GetEncoding ( "ISO-8859-1" ) . GetString ( bytes ) ;
57+ }
58+
59+ private string DecodeUtf8 ( byte [ ] bytes )
60+ {
61+ return Encoding . UTF8 . GetString ( bytes ) ;
5562 }
5663
5764 [ Fact ]
58- async public Task ResponseCanBeUTF8IfConfigured ( )
65+ async public Task ResponseCanBeLatin1IfConfigured ( )
5966 {
6067 var response = await client . GetAsync ( "/endpoint2" ) ;
6168 var bytes = await response . Content . ReadAsByteArrayAsync ( ) ;
62- var str = Encoding . GetEncoding ( "ISO-8859-1" ) . GetString ( bytes ) ;
63- Assert . NotEqual ( "æøå" , str ) ;
64-
65- var utf8string = Encoding . UTF8 . GetString ( bytes ) ;
66- Assert . Equal ( "æøå" , utf8string ) ;
69+ Assert . Equal ( "æøå" , DecodeLatin1 ( bytes ) ) ;
70+ Assert . NotEqual ( "æøå" , DecodeUtf8 ( bytes ) ) ;
6771 }
6872
6973 [ Fact ]
7074 async public Task ResponseHasCharsetInHeader ( )
7175 {
7276 var response = await client . GetAsync ( "/endpoint1" ) ;
7377 Assert . Equal ( "text/plain" , response . Content . Headers . ContentType . MediaType ) ;
74- Assert . Equal ( "iso-8859-1 " , response . Content . Headers . ContentType . CharSet ) ;
78+ Assert . Equal ( "utf-8 " , response . Content . Headers . ContentType . CharSet ) ;
7579
7680 response = await client . GetAsync ( "/endpoint2" ) ;
7781 Assert . Equal ( "text/plain" , response . Content . Headers . ContentType . MediaType ) ;
78- Assert . Equal ( "utf-8 " , response . Content . Headers . ContentType . CharSet ) ;
82+ Assert . Equal ( "iso-8859-1 " , response . Content . Headers . ContentType . CharSet ) ;
7983 }
8084
8185 //[Fact]
0 commit comments