Skip to content

Commit 3981b02

Browse files
authored
CSHARP-5381: Add valid-pass and valid-fail tests for $$matchAsRoot and $$matchAsDocument operators (#1655)
1 parent d47a28c commit 3981b02

File tree

11 files changed

+927
-2
lines changed

11 files changed

+927
-2
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
{
2+
"description": "operator-matchAsDocument",
3+
"schemaVersion": "1.13",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "test"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "coll0",
28+
"databaseName": "test",
29+
"documents": [
30+
{
31+
"_id": 1,
32+
"json": "{ \"x\": 1, \"y\": 2 }"
33+
},
34+
{
35+
"_id": 2,
36+
"json": "1"
37+
},
38+
{
39+
"_id": 3,
40+
"json": "[ \"foo\" ]"
41+
},
42+
{
43+
"_id": 4,
44+
"json": "{ \"x\" }"
45+
}
46+
]
47+
}
48+
],
49+
"tests": [
50+
{
51+
"description": "matchAsDocument with non-matching filter",
52+
"operations": [
53+
{
54+
"name": "find",
55+
"object": "collection0",
56+
"arguments": {
57+
"filter": {
58+
"_id": 1
59+
},
60+
"limit": 1
61+
},
62+
"expectResult": [
63+
{
64+
"_id": 1,
65+
"json": {
66+
"$$matchAsDocument": {
67+
"x": 1,
68+
"y": "two"
69+
}
70+
}
71+
}
72+
]
73+
}
74+
]
75+
},
76+
{
77+
"description": "matchAsDocument evaluates special operators",
78+
"operations": [
79+
{
80+
"name": "find",
81+
"object": "collection0",
82+
"arguments": {
83+
"filter": {
84+
"_id": 1
85+
},
86+
"limit": 1
87+
},
88+
"expectResult": [
89+
{
90+
"_id": 1,
91+
"json": {
92+
"$$matchAsDocument": {
93+
"x": 1,
94+
"y": {
95+
"$$exists": false
96+
}
97+
}
98+
}
99+
}
100+
]
101+
}
102+
]
103+
},
104+
{
105+
"description": "matchAsDocument does not permit extra fields",
106+
"operations": [
107+
{
108+
"name": "find",
109+
"object": "collection0",
110+
"arguments": {
111+
"filter": {
112+
"_id": 1
113+
},
114+
"limit": 1
115+
},
116+
"expectResult": [
117+
{
118+
"_id": 1,
119+
"json": {
120+
"$$matchAsDocument": {
121+
"x": 1
122+
}
123+
}
124+
}
125+
]
126+
}
127+
]
128+
},
129+
{
130+
"description": "matchAsDocument expects JSON object but given scalar",
131+
"operations": [
132+
{
133+
"name": "find",
134+
"object": "collection0",
135+
"arguments": {
136+
"filter": {
137+
"_id": 2
138+
},
139+
"limit": 1
140+
},
141+
"expectResult": [
142+
{
143+
"_id": 2,
144+
"json": {
145+
"$$matchAsDocument": {
146+
"$$matchAsRoot": {}
147+
}
148+
}
149+
}
150+
]
151+
}
152+
]
153+
},
154+
{
155+
"description": "matchAsDocument expects JSON object but given array",
156+
"operations": [
157+
{
158+
"name": "find",
159+
"object": "collection0",
160+
"arguments": {
161+
"filter": {
162+
"_id": 3
163+
},
164+
"limit": 1
165+
},
166+
"expectResult": [
167+
{
168+
"_id": 3,
169+
"json": {
170+
"$$matchAsDocument": {
171+
"$$matchAsRoot": {}
172+
}
173+
}
174+
}
175+
]
176+
}
177+
]
178+
},
179+
{
180+
"description": "matchAsDocument fails to decode Extended JSON",
181+
"operations": [
182+
{
183+
"name": "find",
184+
"object": "collection0",
185+
"arguments": {
186+
"filter": {
187+
"_id": 4
188+
},
189+
"limit": 1
190+
},
191+
"expectResult": [
192+
{
193+
"_id": 4,
194+
"json": {
195+
"$$matchAsDocument": {
196+
"$$matchAsRoot": {}
197+
}
198+
}
199+
}
200+
]
201+
}
202+
]
203+
}
204+
]
205+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
description: operator-matchAsDocument
2+
3+
schemaVersion: "1.13"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
- database:
9+
id: &database0 database0
10+
client: *client0
11+
databaseName: &database0Name test
12+
- collection:
13+
id: &collection0 collection0
14+
database: *database0
15+
collectionName: &collection0Name coll0
16+
17+
initialData:
18+
- collectionName: *collection0Name
19+
databaseName: *database0Name
20+
documents:
21+
- { _id: 1, json: '{ "x": 1, "y": 2 }' }
22+
# Documents with non-objects or invalid JSON
23+
- { _id: 2, json: '1' }
24+
- { _id: 3, json: '[ "foo" ]' }
25+
- { _id: 4, json: '{ "x" }' }
26+
27+
tests:
28+
- description: matchAsDocument with non-matching filter
29+
operations:
30+
- name: find
31+
object: *collection0
32+
arguments:
33+
filter: { _id : 1 }
34+
limit: 1
35+
expectResult:
36+
- { _id: 1, json: { $$matchAsDocument: { x: 1, y: "two" } } }
37+
-
38+
description: matchAsDocument evaluates special operators
39+
operations:
40+
- name: find
41+
object: *collection0
42+
arguments:
43+
filter: { _id : 1 }
44+
limit: 1
45+
expectResult:
46+
- { _id: 1, json: { $$matchAsDocument: { x: 1, y: { $$exists: false } } } }
47+
-
48+
description: matchAsDocument does not permit extra fields
49+
operations:
50+
- name: find
51+
object: *collection0
52+
arguments:
53+
filter: { _id : 1 }
54+
limit: 1
55+
expectResult:
56+
- { _id: 1, json: { $$matchAsDocument: { x: 1 } } }
57+
-
58+
description: matchAsDocument expects JSON object but given scalar
59+
operations:
60+
- name: find
61+
object: *collection0
62+
arguments:
63+
filter: { _id : 2 }
64+
limit: 1
65+
expectResult:
66+
# The following $$matchAsRoot expression would match any document, so
67+
# this ensures the failure is due to the actual value.
68+
- { _id: 2, json: &match_any_document { $$matchAsDocument: { $$matchAsRoot: { } } } }
69+
-
70+
description: matchAsDocument expects JSON object but given array
71+
operations:
72+
- name: find
73+
object: *collection0
74+
arguments:
75+
filter: { _id : 3 }
76+
limit: 1
77+
expectResult:
78+
- { _id: 3, json: *match_any_document }
79+
-
80+
description: matchAsDocument fails to decode Extended JSON
81+
operations:
82+
- name: find
83+
object: *collection0
84+
arguments:
85+
filter: { _id : 4 }
86+
limit: 1
87+
expectResult:
88+
- { _id: 4, json: *match_any_document }
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"description": "operator-matchAsRoot",
3+
"schemaVersion": "1.13",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "test"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "coll0",
28+
"databaseName": "test",
29+
"documents": [
30+
{
31+
"_id": 1,
32+
"x": {
33+
"y": 2,
34+
"z": 3
35+
}
36+
}
37+
]
38+
}
39+
],
40+
"tests": [
41+
{
42+
"description": "matchAsRoot with nested document does not match",
43+
"operations": [
44+
{
45+
"name": "find",
46+
"object": "collection0",
47+
"arguments": {
48+
"filter": {
49+
"_id": 1
50+
},
51+
"limit": 1
52+
},
53+
"expectResult": [
54+
{
55+
"_id": 1,
56+
"x": {
57+
"$$matchAsRoot": {
58+
"y": 3
59+
}
60+
}
61+
}
62+
]
63+
}
64+
]
65+
}
66+
]
67+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
description: operator-matchAsRoot
2+
3+
schemaVersion: "1.13"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
- database:
9+
id: &database0 database0
10+
client: *client0
11+
databaseName: &database0Name test
12+
- collection:
13+
id: &collection0 collection0
14+
database: *database0
15+
collectionName: &collection0Name coll0
16+
17+
initialData:
18+
- collectionName: *collection0Name
19+
databaseName: *database0Name
20+
documents:
21+
- { _id: 1, x: { y: 2, z: 3 } }
22+
23+
tests:
24+
-
25+
description: matchAsRoot with nested document does not match
26+
operations:
27+
- name: find
28+
object: *collection0
29+
arguments:
30+
filter: { _id : 1 }
31+
limit: 1
32+
expectResult:
33+
- { _id: 1, x: { $$matchAsRoot: { y: 3 } } }

0 commit comments

Comments
 (0)