File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
sdk/cosmos/azure_data_cosmos/src/models Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -266,6 +266,18 @@ mod tests {
266
266
Ok ( ( ) )
267
267
}
268
268
269
+ #[ test]
270
+ pub fn serialize_condition ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
271
+ let patch_document = PatchDocument :: default ( ) . with_condition ( "from c where c.value = 0" ) ;
272
+
273
+ let serialized = serde_json:: to_string ( & patch_document) . unwrap ( ) ;
274
+ assert_eq ! (
275
+ serialized,
276
+ "{\" condition\" :\" from c where c.value = 0\" ,\" operations\" :[]}"
277
+ ) ;
278
+ Ok ( ( ) )
279
+ }
280
+
269
281
#[ test]
270
282
pub fn serialize_add ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
271
283
let patch_document = PatchDocument :: default ( ) . with_add (
@@ -391,6 +403,30 @@ mod tests {
391
403
Ok ( ( ) )
392
404
}
393
405
406
+ #[ test]
407
+ pub fn cosmos_docs_conditional_patch_example ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
408
+ const TEST_DOC : & str = r#"{
409
+ "condition": "from c where c.Address.ZipCode = '98101'",
410
+ "operations": [
411
+ {
412
+ "op":"replace",
413
+ "path":"/Address/ZipCode",
414
+ "value":98107
415
+ }
416
+ ]
417
+ }"# ;
418
+
419
+ let doc: PatchDocument = serde_json:: from_str ( TEST_DOC ) ?;
420
+
421
+ assert_eq ! (
422
+ doc,
423
+ PatchDocument :: default ( )
424
+ . with_condition( "from c where c.Address.ZipCode = '98101'" )
425
+ . with_replace( "/Address/ZipCode" , 98107 ) ?
426
+ ) ;
427
+ Ok ( ( ) )
428
+ }
429
+
394
430
#[ test]
395
431
pub fn to_json_number_f64 ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
396
432
assert_eq ! (
You can’t perform that action at this time.
0 commit comments