Skip to content

Commit 23dc1e5

Browse files
authored
CSHARP-5391: Add spec test for $$type operator with "number" (#1739)
1 parent 070f50b commit 23dc1e5

File tree

3 files changed

+240
-1
lines changed

3 files changed

+240
-1
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"description": "operator-type-number_alias",
3+
"schemaVersion": "1.0",
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+
],
32+
"tests": [
33+
{
34+
"description": "type number alias matches int32",
35+
"operations": [
36+
{
37+
"name": "insertOne",
38+
"object": "collection0",
39+
"arguments": {
40+
"document": {
41+
"_id": 1,
42+
"x": {
43+
"$numberInt": "2147483647"
44+
}
45+
}
46+
}
47+
},
48+
{
49+
"name": "find",
50+
"object": "collection0",
51+
"arguments": {
52+
"filter": {
53+
"_id": 1
54+
},
55+
"limit": 1
56+
},
57+
"expectResult": [
58+
{
59+
"_id": 1,
60+
"x": {
61+
"$$type": "number"
62+
}
63+
}
64+
]
65+
}
66+
]
67+
},
68+
{
69+
"description": "type number alias matches int64",
70+
"operations": [
71+
{
72+
"name": "insertOne",
73+
"object": "collection0",
74+
"arguments": {
75+
"document": {
76+
"_id": 1,
77+
"x": {
78+
"$numberLong": "9223372036854775807"
79+
}
80+
}
81+
}
82+
},
83+
{
84+
"name": "find",
85+
"object": "collection0",
86+
"arguments": {
87+
"filter": {
88+
"_id": 1
89+
},
90+
"limit": 1
91+
},
92+
"expectResult": [
93+
{
94+
"_id": 1,
95+
"x": {
96+
"$$type": "number"
97+
}
98+
}
99+
]
100+
}
101+
]
102+
},
103+
{
104+
"description": "type number alias matches double",
105+
"operations": [
106+
{
107+
"name": "insertOne",
108+
"object": "collection0",
109+
"arguments": {
110+
"document": {
111+
"_id": 1,
112+
"x": {
113+
"$numberDouble": "2.71828"
114+
}
115+
}
116+
}
117+
},
118+
{
119+
"name": "find",
120+
"object": "collection0",
121+
"arguments": {
122+
"filter": {
123+
"_id": 1
124+
},
125+
"limit": 1
126+
},
127+
"expectResult": [
128+
{
129+
"_id": 1,
130+
"x": {
131+
"$$type": "number"
132+
}
133+
}
134+
]
135+
}
136+
]
137+
},
138+
{
139+
"description": "type number alias matches decimal128",
140+
"operations": [
141+
{
142+
"name": "insertOne",
143+
"object": "collection0",
144+
"arguments": {
145+
"document": {
146+
"_id": 1,
147+
"x": {
148+
"$numberDecimal": "3.14159"
149+
}
150+
}
151+
}
152+
},
153+
{
154+
"name": "find",
155+
"object": "collection0",
156+
"arguments": {
157+
"filter": {
158+
"_id": 1
159+
},
160+
"limit": 1
161+
},
162+
"expectResult": [
163+
{
164+
"_id": 1,
165+
"x": {
166+
"$$type": "number"
167+
}
168+
}
169+
]
170+
}
171+
]
172+
}
173+
]
174+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
description: operator-type-number_alias
2+
3+
schemaVersion: "1.0"
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+
22+
tests:
23+
-
24+
description: type number alias matches int32
25+
operations:
26+
- name: insertOne
27+
object: *collection0
28+
arguments:
29+
document: { _id: 1, x: { $numberInt: "2147483647" } }
30+
- &find
31+
name: find
32+
object: *collection0
33+
arguments:
34+
filter: { _id: 1 }
35+
limit: 1
36+
expectResult:
37+
- { _id: 1, x: { $$type: "number" } }
38+
-
39+
description: type number alias matches int64
40+
operations:
41+
- name: insertOne
42+
object: *collection0
43+
arguments:
44+
document: { _id: 1, x: { $numberLong: "9223372036854775807" } }
45+
- *find
46+
-
47+
description: type number alias matches double
48+
operations:
49+
- name: insertOne
50+
object: *collection0
51+
arguments:
52+
document: { _id: 1, x: { $numberDouble: "2.71828" } }
53+
- *find
54+
-
55+
description: type number alias matches decimal128
56+
operations:
57+
- name: insertOne
58+
object: *collection0
59+
arguments:
60+
document: { _id: 1, x: { $numberDecimal: "3.14159" } }
61+
- *find

tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedValueMatcher.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using System.Collections;
1718
using System.Collections.Generic;
1819
using System.Linq;
1920
using FluentAssertions;
@@ -26,6 +27,8 @@ namespace MongoDB.Driver.Tests.UnifiedTestOperations.Matchers
2627
{
2728
public class UnifiedValueMatcher
2829
{
30+
private static readonly List<string> __numericTypes = ["int", "long", "double", "decimal"];
31+
2932
private UnifiedEntityMap _entityMap;
3033

3134
public UnifiedValueMatcher(UnifiedEntityMap entityMap)
@@ -197,7 +200,8 @@ private void AssertExpectedType(BsonValue actual, BsonValue expectedTypes)
197200

198201
if (expectedTypes.IsString)
199202
{
200-
expectedTypeNames = new List<string> { expectedTypes.AsString };
203+
var expectedType = expectedTypes.AsString;
204+
expectedTypeNames = expectedType == "number" ? __numericTypes : [expectedType];
201205
}
202206
else if (expectedTypes.IsBsonArray)
203207
{

0 commit comments

Comments
 (0)