Skip to content

Commit e8a6439

Browse files
committed
Default encoding utf-8
1 parent 7b1e336 commit e8a6439

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

UnitTests/TestResponseHasCorrectEncoding.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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]

netmockery/JSONReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ from jsonreplacement in replacements
159159
simpleResponseCreator.Replacements = new BodyReplacement[0];
160160
}
161161

162-
Debug.Assert(simpleResponseCreator.Encoding == Encoding.GetEncoding("iso-8859-1"));
162+
Debug.Assert(simpleResponseCreator.Encoding == Encoding.UTF8);
163163
if (charset != null)
164164
{
165165
simpleResponseCreator.Encoding = Encoding.GetEncoding(charset);

netmockery/ResponseCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public override async Task<byte[]> CreateResponseAsync(IHttpRequestWrapper reque
127127
}
128128
public string ContentType { get; set; }
129129
public abstract string GetBody(RequestInfo requestInfo);
130-
public Encoding Encoding { get; set; } = Encoding.GetEncoding("ISO-8859-1");
130+
public Encoding Encoding { get; set; } = Encoding.UTF8;
131131

132132
public BodyReplacement[] Replacements = new BodyReplacement[0];
133133

0 commit comments

Comments
 (0)