@@ -2469,22 +2469,30 @@ TEST_F(Crud, single_document)
2469
2469
Schema sch = getSchema (" test" );
2470
2470
Collection coll = sch.createCollection (" c1" , true );
2471
2471
2472
+ cout << " Adding documents..." << endl;
2473
+
2472
2474
coll.remove (" true" ).execute ();
2473
2475
2474
- coll.add (R"( {"_id":"id1", "name":"foo", "age": 1 })" )
2475
- .add (R"( {"_id":"id2", "name":"bar", "age": 2 })" )
2476
- .add (R"( {"_id":"id3", "name":"baz", "age": 3 })" )
2477
- .execute ();
2476
+ coll.add (R"( {"_id":"id1", "name":"foo", "age": 1 })" )
2477
+ .add (R"( {"_id":"id2", "name":"bar", "age": 2 })" )
2478
+ .add (R"( {"_id":"id3", "name":"baz", "age": 3 })" )
2479
+ .execute ();
2480
+
2481
+ cout << " getOne()" << endl;
2478
2482
2479
2483
EXPECT_EQ (string (" foo" ), coll.getOne (" id1" )[" name" ].get <string>());
2480
2484
EXPECT_EQ (string (" bar" ), coll.getOne (" id2" )[" name" ].get <string>());
2481
2485
EXPECT_TRUE (coll.getOne (" idZ" ).isNull ());
2482
2486
2487
+ cout << " removeOne()" << endl;
2488
+
2483
2489
EXPECT_EQ (1 , coll.removeOne (" id1" ).getAffectedItemsCount ());
2484
2490
EXPECT_EQ (0 , coll.removeOne (" id1" ).getAffectedItemsCount ());
2485
2491
2486
2492
EXPECT_TRUE (coll.getOne (" id1" ).isNull ());
2487
2493
2494
+ cout << " replaceOne()" << endl;
2495
+
2488
2496
// Replace existing document
2489
2497
EXPECT_EQ (1 , coll.replaceOne (
2490
2498
" id3" ,
@@ -2493,6 +2501,8 @@ TEST_F(Crud, single_document)
2493
2501
EXPECT_EQ (string (" qux" ), coll.getOne (" id3" )[" name" ].get <string>());
2494
2502
EXPECT_EQ (4 , coll.getOne (" id3" )[" age" ].get <int >());
2495
2503
2504
+ cout << " replaceOne(): change id" << endl;
2505
+
2496
2506
// Setting a different _id on document should throw error
2497
2507
// Document passed as string
2498
2508
EXPECT_THROW (coll.replaceOne (" id3" , " {\" _id\" : \" id4\" , \" name\" : \" baz\" }" ),
@@ -2508,13 +2518,20 @@ TEST_F(Crud, single_document)
2508
2518
// Document passed as DbDoc
2509
2519
EXPECT_THROW (coll.replaceOne (" id3" , DbDoc (" {\" _id\" : \" id4\" , \" name\" : \" baz\" }" )),
2510
2520
Error);
2521
+
2522
+ cout << " getOne(): array" << endl;
2523
+
2511
2524
EXPECT_EQ (string (" qux" ), coll.getOne (" id3" )[" name" ].get <string>());
2512
2525
EXPECT_EQ (string (" id3" ), coll.getOne (" id3" )[" _id" ].get <string>());
2513
2526
2527
+ cout << " replaceOne(): non-existing" << endl;
2528
+
2514
2529
// should affect none
2515
2530
EXPECT_EQ (0 ,
2516
2531
coll.replaceOne (" id4" , expr (R"( {"name": "baz" })" ))
2517
2532
.getAffectedItemsCount ());
2533
+
2534
+ cout << " Done!" << endl;
2518
2535
}
2519
2536
2520
2537
0 commit comments