1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Dynamic ;
44using Microsoft . VisualStudio . TestTools . UnitTesting ;
@@ -10,8 +10,7 @@ namespace Senparc.CO2NET.Tests.Helpers
1010 [ TestClass ]
1111 public class SerializerHelperJsonTests
1212 {
13- #region 复杂条件下的序列化测试:忽略null、特定值值、特定属性测试(微信接口中尤其重要)
14- [ TestMethod ]
13+ #region Serialization Test Under Complex Conditions: Ignore null, specific values, specific properties (especially important in WeChat interfaces) [TestMethod]
1514 public void GetJsonStringTest_Null ( )
1615 {
1716 var obj =
@@ -37,7 +36,7 @@ public void GetJsonStringTest_Null()
3736 var dt1 = SystemTime . Now ;
3837
3938 {
40- //不进行任何设置,返回原始JSON
39+ // Do not modify any properties, keep the original JSON
4140 var json = SerializerHelper . GetJsonString ( obj , jsonSetting : null ) ;
4241 Console . WriteLine ( json ) ;
4342 var exceptedJson = "{\" X\" :{\" A\" :\" Jeffrey\" ,\" B\" :31,\" C\" :null,\" ElementClassA\" :{\" A\" :\" Jeffrey\" ,\" B\" :null,\" RootClass\" :null},\" ElementClassB\" :null,\" ElementClass2\" :null},\" Y\" :{\" O\" :\" 0\" ,\" Z\" :null}}" ;
@@ -46,15 +45,15 @@ public void GetJsonStringTest_Null()
4645
4746
4847 {
49- //不忽略任何属性
48+ // Do not modify any properties
5049 var json = SerializerHelper . GetJsonString ( obj , new JsonSetting ( false ) ) ;
5150 Console . WriteLine ( json ) ;
5251 var exceptedJson = "{\" X\" :{\" A\" :\" Jeffrey\" ,\" B\" :31,\" ElementClassA\" :{\" A\" :\" Jeffrey\" ,\" B\" :null,\" RootClass\" :null},\" ElementClassB\" :null,\" ElementClass2\" :null},\" Y\" :{\" O\" :\" 0\" ,\" Z\" :null}}" ;
5352 Assert . AreEqual ( exceptedJson , json ) ;
5453 }
5554
5655 {
57- //忽略所有为null的属性
56+ // If the property is null, ignore it
5857 var json = SerializerHelper . GetJsonString ( obj , new JsonSetting ( true ) ) ;
5958 Console . WriteLine ( json ) ;
6059 var exceptedJson = "{\" X\" :{\" A\" :\" Jeffrey\" ,\" B\" :31,\" ElementClassA\" :{\" A\" :\" Jeffrey\" }},\" Y\" :{\" O\" :\" 0\" }}" ;
@@ -80,75 +79,75 @@ public void GetJsonStringTest_Null()
8079 }
8180
8281 {
83- //忽略特定为null的属性
82+ // If the property is null, ignore it
8483 var json = SerializerHelper . GetJsonString ( obj ,
85- new JsonSetting ( false , new List < string > ( new [ ] { "Z" } ) ) ) ; //Z属性会被忽略
84+ new JsonSetting ( false , new List < string > ( new [ ] { "Z" } ) ) ) ; // Z property will be ignored
8685 Console . WriteLine ( json ) ;
8786 var exceptedJson = "{\" X\" :{\" A\" :\" Jeffrey\" ,\" B\" :31,\" ElementClassA\" :{\" A\" :\" Jeffrey\" ,\" B\" :null,\" RootClass\" :null},\" ElementClassB\" :null,\" ElementClass2\" :null},\" Y\" :{\" O\" :\" 0\" }}" ;
8887 Assert . AreEqual ( exceptedJson , json ) ;
8988 }
9089
9190 {
92- //忽略特定值测试(忽略特定值,以及忽略null)
91+ // The property value is optional, it can be the property value itself or null
9392 var obj4 = new RootClass ( )
9493 {
95- A = "IGNORE" , //会被忽略
94+ A = "IGNORE" , // Will be ignored
9695 B = 31 ,
9796 C = null ,
9897 ElementClassA = null ,
9998 ElementClassB = null ,
10099 ElementClass2 = null
101100 } ;
102- var json = SerializerHelper . GetJsonString ( obj4 , new JsonSetting ( true ) ) ; //Z属性会被忽略
101+ var json = SerializerHelper . GetJsonString ( obj4 , new JsonSetting ( true ) ) ; // Z property will be ignored
103102 Console . WriteLine ( json ) ;
104103 var exceptedJson = "{\" B\" :31}" ;
105104 Assert . AreEqual ( exceptedJson , json ) ;
106105 }
107106
108107 {
109- //忽略特定值测试(只忽略特定值,不忽略null)
108+ // The property value is optional, only the property value itself or null
110109 var obj4 = new RootClass ( )
111110 {
112- A = "IGNORE" , //会被忽略
111+ A = "IGNORE" , // Will be ignored
113112 B = 31 ,
114113 C = null ,
115114 ElementClassA = null ,
116115 ElementClassB = null ,
117116 ElementClass2 = null
118117 } ;
119- var json = SerializerHelper . GetJsonString ( obj4 , new JsonSetting ( false ) ) ; //Z属性会被忽略
118+ var json = SerializerHelper . GetJsonString ( obj4 , new JsonSetting ( false ) ) ; // Z property will be ignored
120119 Console . WriteLine ( json ) ;
121120 var exceptedJson = "{\" B\" :31,\" ElementClassA\" :null,\" ElementClassB\" :null,\" ElementClass2\" :null}" ;
122121 Assert . AreEqual ( exceptedJson , json ) ;
123122 }
124123
125124 {
126- //忽略特定值测试(不匹配,因此不忽略)
125+ // The property value is optional, match it, but it is not required
127126 var obj4 = new RootClass ( )
128127 {
129- A = "DO NET IGNORE" , //不会被忽略
128+ A = "DO NET IGNORE" , // Will be ignored
130129 B = 31 ,
131130 C = null ,
132131 ElementClassA = null ,
133132 ElementClassB = null ,
134133 ElementClass2 = null
135134 } ;
136- var json = SerializerHelper . GetJsonString ( obj4 , new JsonSetting ( true ) ) ; //Z属性会被忽略
135+ var json = SerializerHelper . GetJsonString ( obj4 , new JsonSetting ( true ) ) ; // Z property will be ignored
137136 Console . WriteLine ( json ) ;
138137 var exceptedJson = "{\" A\" :\" DO NET IGNORE\" ,\" B\" :31}" ;
139138 Assert . AreEqual ( exceptedJson , json ) ;
140139 }
141140
142141 {
143- //忽略特定类型为null的属性
142+ // If the property value is null, ignore it
144143 var obj3 = new RootClass ( )
145144 {
146145 A = "Jeffrey" ,
147146 B = 31 ,
148147 C = null ,
149148 ElementClassA = new ElementClass ( ) { A = "Jeffrey" , B = null } ,
150149 ElementClassB = null ,
151- ElementClass2 = null //将会被忽略
150+ ElementClass2 = null // Will be ignored
152151 } ;
153152
154153 var json3 = SerializerHelper . GetJsonString ( obj3 ,
@@ -198,7 +197,7 @@ public class ElementClass2
198197 #endregion
199198
200199
201- #region 复杂(嵌套类型)反序列化测试
200+ #region Complex (Nested Type) Deserialization Test
202201
203202 [ TestMethod ]
204203 public void GetObjectTest ( )
@@ -219,7 +218,7 @@ public void GetObjectTest()
219218 #endregion
220219
221220
222- #region 简单序列化/反序列化测试
221+ #region Simple Serialization/Deserialization Test
223222
224223 [ TestMethod ]
225224 public void Simple_GetJsonStringTest ( )
@@ -266,7 +265,7 @@ public class Data
266265
267266 #endregion
268267
269- #region ExpandoObject类型转换测试
268+ #region ExpandoObject Type Conversion Test
270269
271270 [ TestMethod ]
272271 public void GetJsonStringTest_Expando ( )
0 commit comments