1+ // Copyright (c) Arjen Post. See License.txt and Notice.txt in the project root for license information.
2+
13using System . Collections . Generic ;
24using System . IO ;
35using System . Text ;
@@ -25,10 +27,10 @@ public void TheSerializeMethodShouldFilterArrayElements()
2527 var value = new List < dynamic > { new { foo = "bar" , baz = "qux" } } ;
2628
2729 // Act
28- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" ) ;
30+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" ) ;
2931
3032 // Assert
31- Assert . Equal ( "[{\" foo\" :\" bar\" }]" , result . ToString ( ) ) ;
33+ Assert . Equal ( "[{\" foo\" :\" bar\" }]" , this . result . ToString ( ) ) ;
3234 }
3335
3436 [ Fact ]
@@ -38,10 +40,10 @@ public void TheSerializeMethodShouldRemoveEmptyArray()
3840 var value = new { foo = new List < dynamic > { new { bar = "baz" } } , qux = "quux" } ;
3941
4042 // Act
41- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "qux" ) ;
43+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "qux" ) ;
4244
4345 // Assert
44- Assert . Equal ( "{\" qux\" :\" quux\" }" , result . ToString ( ) ) ;
46+ Assert . Equal ( "{\" qux\" :\" quux\" }" , this . result . ToString ( ) ) ;
4547 }
4648
4749 [ Fact ]
@@ -51,10 +53,10 @@ public void TheSerializeMethodShouldNotRemoveEmptyArrayIfRoot()
5153 var value = new List < dynamic > { new { foo = "bar" } } ;
5254
5355 // Act
54- jsonSerializer . Serialize ( this . jsonWriter , value , _ => false ) ;
56+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => false ) ;
5557
5658 // Assert
57- Assert . Equal ( "[]" , result . ToString ( ) ) ;
59+ Assert . Equal ( "[]" , this . result . ToString ( ) ) ;
5860 }
5961
6062 [ Fact ]
@@ -64,10 +66,10 @@ public void TheSerializeMethodShouldFilterObjectPropertiesInsideArrayElement()
6466 var value = new List < dynamic > { new { foo = new { bar = "baz" , qux = "quux" } } } ;
6567
6668 // Act
67- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
69+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
6870
6971 // Assert
70- Assert . Equal ( "[{\" foo\" :{\" bar\" :\" baz\" }}]" , result . ToString ( ) ) ;
72+ Assert . Equal ( "[{\" foo\" :{\" bar\" :\" baz\" }}]" , this . result . ToString ( ) ) ;
7173 }
7274
7375 [ Fact ]
@@ -77,10 +79,10 @@ public void TheSerializeMethodShouldFilterObjectProperties()
7779 var value = new { foo = "bar" , baz = "qux" } ;
7880
7981 // Act
80- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" ) ;
82+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" ) ;
8183
8284 // Assert
83- Assert . Equal ( "{\" foo\" :\" bar\" }" , result . ToString ( ) ) ;
85+ Assert . Equal ( "{\" foo\" :\" bar\" }" , this . result . ToString ( ) ) ;
8486 }
8587
8688 [ Fact ]
@@ -90,10 +92,10 @@ public void TheSerializeMethodShouldRemoveEmptyObject()
9092 var value = new { foo = new { bar = "baz" } , qux = "quux" } ;
9193
9294 // Act
93- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "qux" ) ;
95+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "qux" ) ;
9496
9597 // Assert
96- Assert . Equal ( "{\" qux\" :\" quux\" }" , result . ToString ( ) ) ;
98+ Assert . Equal ( "{\" qux\" :\" quux\" }" , this . result . ToString ( ) ) ;
9799 }
98100
99101 [ Fact ]
@@ -103,10 +105,10 @@ public void TheSerializeMethodShouldNotRemoveEmptyObjectIfRoot()
103105 var value = new { foo = "bar" } ;
104106
105107 // Act
106- jsonSerializer . Serialize ( this . jsonWriter , value , _ => false ) ;
108+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => false ) ;
107109
108110 // Assert
109- Assert . Equal ( "{}" , result . ToString ( ) ) ;
111+ Assert . Equal ( "{}" , this . result . ToString ( ) ) ;
110112 }
111113
112114 [ Fact ]
@@ -116,10 +118,10 @@ public void TheSerializeMethodShouldFilterObjectPropertiesInsideObjectProperties
116118 var value = new { foo = new { bar = "baz" , qux = "quux" } } ;
117119
118120 // Act
119- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
121+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
120122
121123 // Assert
122- Assert . Equal ( "{\" foo\" :{\" bar\" :\" baz\" }}" , result . ToString ( ) ) ;
124+ Assert . Equal ( "{\" foo\" :{\" bar\" :\" baz\" }}" , this . result . ToString ( ) ) ;
123125 }
124126
125127 [ Fact ]
@@ -129,10 +131,10 @@ public void TheSerializeMethodShouldFilterArrayElementsInsideObjectProperties()
129131 var value = new { foo = new List < dynamic > { new { bar = "baz" , qux = "quux" } } } ;
130132
131133 // Act
132- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
134+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
133135
134136 // Assert
135- Assert . Equal ( "{\" foo\" :[{\" bar\" :\" baz\" }]}" , result . ToString ( ) ) ;
137+ Assert . Equal ( "{\" foo\" :[{\" bar\" :\" baz\" }]}" , this . result . ToString ( ) ) ;
136138 }
137139
138140 [ Fact ]
@@ -142,10 +144,10 @@ public void TheSerializeMethodShouldFilterArrayElementInsideArrayElement()
142144 var value = new List < dynamic > { new { foo = new List < dynamic > { new { bar = "baz" , qux = "quux" } } } } ;
143145
144146 // Act
145- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
147+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" || _ == "foo/bar" ) ;
146148
147149 // Assert
148- Assert . Equal ( "[{\" foo\" :[{\" bar\" :\" baz\" }]}]" , result . ToString ( ) ) ;
150+ Assert . Equal ( "[{\" foo\" :[{\" bar\" :\" baz\" }]}]" , this . result . ToString ( ) ) ;
149151 }
150152
151153 [ Fact ]
@@ -155,8 +157,15 @@ public void TheSerializeMethodShouldApplyCaching()
155157 var value = new List < dynamic > { new { foo = "bar" } , new { foo = "bar" } } ;
156158 var count = 0 ;
157159
160+ bool shouldSerialize ( string path )
161+ {
162+ count ++ ;
163+
164+ return path == "foo" ;
165+ }
166+
158167 // Act
159- jsonSerializer . Serialize ( this . jsonWriter , value , _ => { count ++ ; return _ == "foo" ; } ) ;
168+ this . jsonSerializer . Serialize ( this . jsonWriter , value , shouldSerialize ) ;
160169
161170 // Assert
162171 Assert . Equal ( 1 , count ) ;
@@ -169,10 +178,10 @@ public void TheSerializeMethodFilterCorrectlyUsingCache()
169178 var value = new List < dynamic > { new { foo = "bar" , baz = "qux" } , new { foo = "bar" , baz = "qux" } } ;
170179
171180 // Act
172- jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" ) ;
181+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => _ == "foo" ) ;
173182
174183 // Assert
175- Assert . Equal ( "[{\" foo\" :\" bar\" },{\" foo\" :\" bar\" }]" , result . ToString ( ) ) ;
184+ Assert . Equal ( "[{\" foo\" :\" bar\" },{\" foo\" :\" bar\" }]" , this . result . ToString ( ) ) ;
176185 }
177186
178187 [ Fact ]
@@ -182,10 +191,10 @@ public void TheSerializeMethodShouldFilterArrayElementInsideArrayElement2()
182191 var value = new { totalCount = 0 , data = new object [ 0 ] } ;
183192
184193 // Act
185- jsonSerializer . Serialize ( this . jsonWriter , value , _ => true ) ;
194+ this . jsonSerializer . Serialize ( this . jsonWriter , value , _ => true ) ;
186195
187196 // Assert
188- Assert . Equal ( "{\" totalCount\" :0,\" data\" :[]}" , result . ToString ( ) ) ;
197+ Assert . Equal ( "{\" totalCount\" :0,\" data\" :[]}" , this . result . ToString ( ) ) ;
189198 }
190199 }
191200}
0 commit comments