@@ -85,6 +85,24 @@ public void FindValue_ReturnsCorrectValue(JToken root, string key, JValue expect
8585 . Which . Should < JValue > ( ) . Be ( expected ) ;
8686 }
8787
88+ [ Fact ]
89+ public void FindValue_ReturnsNullIfKeyDoesNotExist ( )
90+ {
91+ var document = new JsonDocument ( JObject . Parse ( @"{ ""key"": ""value"" }" ) ) ;
92+ var actual = document . FindToken ( "notkey" ) ;
93+
94+ actual . Should ( ) . BeNull ( ) ;
95+ }
96+
97+ [ Fact ]
98+ public void FindValue_ReturnsNullIfKeyDoesNotExist_ButSubkeyExists ( )
99+ {
100+ var document = new JsonDocument ( JObject . Parse ( @"{ ""key"": ""value"" }" ) ) ;
101+ var actual = document . FindToken ( "key:nested" ) ;
102+
103+ actual . Should ( ) . BeNull ( ) ;
104+ }
105+
88106 [ Fact ]
89107 public void SetValue_ModifiesOriginalDocument_Object ( )
90108 {
@@ -147,6 +165,63 @@ public void SetValue_CreatesNestedStructure_Array()
147165 . Which . Value . Should ( ) . Be ( "value" ) ; ;
148166 }
149167
168+ [ Fact ]
169+ public void SetValue_ReplacesValue_WithArray ( )
170+ {
171+ var document = new JsonDocument ( JObject . Parse ( @"{ ""key"": ""value"" }" ) ) ;
172+
173+ document . SetValue ( "key:0" , "array" ) ;
174+
175+ document . _json . Should ( ) . BeOfType < JObject > ( )
176+ . Which . Should ( ) . ContainKey ( "key" ) ;
177+
178+ document . _json [ "key" ] . Should ( ) . BeOfType < JArray > ( )
179+ . Which . Should ( ) . HaveCount ( 1 ) ;
180+
181+ document . _json [ "key" ] [ 0 ] . Should ( ) . BeOfType < JValue > ( )
182+ . Which . Value . Should ( ) . Be ( "array" ) ;
183+ }
184+
185+ [ Fact ]
186+ public void SetValue_ReplacesValue_WithObject ( )
187+ {
188+ var document = new JsonDocument ( JObject . Parse ( @"{ ""key"": ""value"" }" ) ) ;
189+
190+ document . SetValue ( "key:nested" , "object" ) ;
191+
192+ document . _json . Should ( ) . BeOfType < JObject > ( )
193+ . Which . Should ( ) . ContainKey ( "key" ) ;
194+
195+ document . _json [ "key" ] . Should ( ) . BeOfType < JObject > ( )
196+ . Which . Should ( ) . ContainKey ( "nested" ) ;
197+
198+ document . _json [ "key" ] [ "nested" ] . Should ( ) . BeOfType < JValue > ( )
199+ . Which . Value . Should ( ) . Be ( "object" ) ;
200+ }
201+
202+ [ Fact ]
203+ public void Merge_MergesTwoDocuments ( )
204+ {
205+ var document1 = new JsonDocument ( JObject . Parse ( @"{ ""key1"": ""value1"" }" ) ) ;
206+ var document2 = new JsonDocument ( JObject . Parse ( @"{ ""key2"": ""value2"" }" ) ) ;
207+
208+ document1 . Merge ( document2 ) ;
209+
210+ document1 . _json . Should ( ) . BeOfType < JObject > ( )
211+ . Which . Should ( ) . ContainKeys ( "key1" , "key1" ) ;
212+
213+ document1 . _json [ "key1" ] . Should ( ) . BeOfType < JValue > ( )
214+ . Which . Value . Should ( ) . Be ( "value1" ) ;
215+ document1 . _json [ "key2" ] . Should ( ) . BeOfType < JValue > ( )
216+ . Which . Value . Should ( ) . Be ( "value2" ) ;
217+ }
218+
219+ [ Fact ( Skip = "not yet implemented" ) ]
220+ public void Merge_ReplacesWholeArray ( )
221+ {
222+ // TODO: Make sure Merge replaces an array instead of only update array indices.
223+ }
224+
150225 [ Fact ]
151226 public void SetValue_CreatesNestedStructure_Multi ( )
152227 {
0 commit comments