Skip to content

Commit 6f3f55d

Browse files
committed
为json操作单元测试添加 TestToJson_ToSingleQuotes 测试方法
1 parent 0ea5590 commit 6f3f55d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

test/Util.Tests/Helpers/JsonTest.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,29 @@ public void TestToJson() {
4949
Assert.Equal( result.ToString(), Json.ToJson( JsonTestSample.Create() ) );
5050
}
5151

52+
/// <summary>
53+
/// 测试转成Json,将双引号转成单引号
54+
/// </summary>
55+
[Fact]
56+
public void TestToJson_ToSingleQuotes() {
57+
var result = new StringBuilder();
58+
result.Append( "{" );
59+
result.Append( "'Name':'a'," );
60+
result.Append( "'nickname':'b'," );
61+
result.Append( "'Value':null," );
62+
result.Append( "'Date':'2012/1/1 0:00:00'," );
63+
result.Append( "'Age':1," );
64+
result.Append( "'isShow':true" );
65+
result.Append( "}" );
66+
Assert.Equal( result.ToString(), Json.ToJson( JsonTestSample.Create(),true ) );
67+
}
68+
5269
/// <summary>
5370
/// 测试转成对象
5471
/// </summary>
5572
[Fact]
5673
public void TestToObject() {
57-
var customer = Json.ToObject<JsonTestSample>( $"{{\"Name\":\"a\"}}" );
74+
var customer = Json.ToObject<JsonTestSample>( "{\"Name\":\"a\"}" );
5875
Assert.Equal( "a", customer.Name );
5976
}
6077
}

0 commit comments

Comments
 (0)