Skip to content

Commit 602d726

Browse files
committed
fix: ToString() return json
1 parent 85d8c40 commit 602d726

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System.Linq;
3+
using System.Text.Json;
4+
5+
namespace SocketIOClient.UnitTest
6+
{
7+
[TestClass]
8+
public class SocketIOResponseTest
9+
{
10+
[TestMethod]
11+
[DataRow("[1]")]
12+
[DataRow("[true]")]
13+
//[DataRow("[undefined]")]
14+
[DataRow("[null]")]
15+
[DataRow("[\"hi\",\"arr\",[1,true,\"vvv\"]]")]
16+
public void TestToString(string json)
17+
{
18+
var array = JsonDocument.Parse(json).RootElement.EnumerateArray().ToList();
19+
var response = new SocketIOResponse(array, null);
20+
Assert.AreEqual(json, response.ToString());
21+
}
22+
}
23+
}

src/SocketIOClient/SocketIOResponse.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Text;
23
using System.Text.Json;
34
using System.Threading.Tasks;
45

@@ -32,7 +33,18 @@ public T GetValue<T>(int index = 0)
3233

3334
public override string ToString()
3435
{
35-
return _array.ToString();
36+
var builder = new StringBuilder();
37+
builder.Append('[');
38+
foreach (var item in _array)
39+
{
40+
builder.Append(item.GetRawText());
41+
if (_array.IndexOf(item) < _array.Count - 1)
42+
{
43+
builder.Append(',');
44+
}
45+
}
46+
builder.Append(']');
47+
return builder.ToString();
3648
}
3749

3850
public async Task CallbackAsync(params object[] data)

0 commit comments

Comments
 (0)