File tree 1 file changed +28
-0
lines changed
sdk/core/azure-core/test/ut
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,31 @@ TEST(Json, create)
16
16
17
17
EXPECT_EQ (expected, j.dump ());
18
18
}
19
+
20
+ TEST (Json, duplicateName)
21
+ {
22
+ json jsonRoot = json::parse (R"( {"KeyName": 1, "AnotherObject": {"KeyName": 2}})" );
23
+ int value = 0 ;
24
+ if (jsonRoot.contains (" KeyName" ))
25
+ {
26
+ value = jsonRoot[" KeyName" ].get <int >();
27
+ }
28
+ EXPECT_EQ (value, 1 );
29
+
30
+ jsonRoot = json::parse (R"( {"AnotherObject": {"KeyName": 2}})" );
31
+ value = 0 ;
32
+
33
+ // The nested KeyName property is considered not found, when at the root.
34
+ if (jsonRoot.contains (" KeyName" ))
35
+ {
36
+ value = jsonRoot[" KeyName" ].get <int >();
37
+ }
38
+ EXPECT_EQ (value, 0 );
39
+
40
+ // The nested KeyName property is considered found, when navigating to the nested object first.
41
+ if (jsonRoot[" AnotherObject" ].contains (" KeyName" ))
42
+ {
43
+ value = jsonRoot[" AnotherObject" ][" KeyName" ].get <int >();
44
+ }
45
+ EXPECT_EQ (value, 2 );
46
+ }
You can’t perform that action at this time.
0 commit comments