Browse Source

CSHARP-5391: Add spec test for $$type operator with "number" (#1739)

main
Adelin Owona 5 days ago
committed by GitHub
parent
commit
23dc1e56c2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 174
      specifications/unified-test-format/tests/valid-pass/operator-type-number_alias.json
  2. 61
      specifications/unified-test-format/tests/valid-pass/operator-type-number_alias.yml
  3. 6
      tests/MongoDB.Driver.Tests/UnifiedTestOperations/Matchers/UnifiedValueMatcher.cs

174
specifications/unified-test-format/tests/valid-pass/operator-type-number_alias.json

@ -0,0 +1,174 @@
{
"description": "operator-type-number_alias",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "test"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "coll0"
}
}
],
"initialData": [
{
"collectionName": "coll0",
"databaseName": "test",
"documents": []
}
],
"tests": [
{
"description": "type number alias matches int32",
"operations": [
{
"name": "insertOne",
"object": "collection0",
"arguments": {
"document": {
"_id": 1,
"x": {
"$numberInt": "2147483647"
}
}
}
},
{
"name": "find",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
},
"limit": 1
},
"expectResult": [
{
"_id": 1,
"x": {
"$$type": "number"
}
}
]
}
]
},
{
"description": "type number alias matches int64",
"operations": [
{
"name": "insertOne",
"object": "collection0",
"arguments": {
"document": {
"_id": 1,
"x": {
"$numberLong": "9223372036854775807"
}
}
}
},
{
"name": "find",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
},
"limit": 1
},
"expectResult": [
{
"_id": 1,
"x": {
"$$type": "number"
}
}
]
}
]
},
{
"description": "type number alias matches double",
"operations": [
{
"name": "insertOne",
"object": "collection0",
"arguments": {
"document": {
"_id": 1,
"x": {
"$numberDouble": "2.71828"
}
}
}
},
{
"name": "find",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
},
"limit": 1
},
"expectResult": [
{
"_id": 1,
"x": {
"$$type": "number"
}
}
]
}
]
},
{
"description": "type number alias matches decimal128",
"operations": [
{
"name": "insertOne",
"object": "collection0",
"arguments": {
"document": {
"_id": 1,
"x": {
"$numberDecimal": "3.14159"
}
}
}
},
{
"name": "find",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
},
"limit": 1
},
"expectResult": [
{
"_id": 1,
"x": {
"$$type": "number"
}
}
]
}
]
}
]
}

61
specifications/unified-test-format/tests/valid-pass/operator-type-number_alias.yml

@ -0,0 +1,61 @@
description: operator-type-number_alias
schemaVersion: "1.0"
createEntities:
- client:
id: &client0 client0
- database:
id: &database0 database0
client: *client0
databaseName: &database0Name test
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name coll0
initialData:
- collectionName: *collection0Name
databaseName: *database0Name
documents: []
tests:
-
description: type number alias matches int32
operations:
- name: insertOne
object: *collection0
arguments:
document: { _id: 1, x: { $numberInt: "2147483647" } }
- &find
name: find
object: *collection0
arguments:
filter: { _id: 1 }
limit: 1
expectResult:
- { _id: 1, x: { $$type: "number" } }
-
description: type number alias matches int64
operations:
- name: insertOne
object: *collection0
arguments:
document: { _id: 1, x: { $numberLong: "9223372036854775807" } }
- *find
-
description: type number alias matches double
operations:
- name: insertOne
object: *collection0
arguments:
document: { _id: 1, x: { $numberDouble: "2.71828" } }
- *find
-
description: type number alias matches decimal128
operations:
- name: insertOne
object: *collection0
arguments:
document: { _id: 1, x: { $numberDecimal: "3.14159" } }
- *find

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

@ -14,6 +14,7 @@
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
@ -26,6 +27,8 @@ namespace MongoDB.Driver.Tests.UnifiedTestOperations.Matchers
{
public class UnifiedValueMatcher
{
private static readonly List<string> __numericTypes = ["int", "long", "double", "decimal"];
private UnifiedEntityMap _entityMap;
public UnifiedValueMatcher(UnifiedEntityMap entityMap)
@ -197,7 +200,8 @@ namespace MongoDB.Driver.Tests.UnifiedTestOperations.Matchers
if (expectedTypes.IsString)
{
expectedTypeNames = new List<string> { expectedTypes.AsString };
var expectedType = expectedTypes.AsString;
expectedTypeNames = expectedType == "number" ? __numericTypes : [expectedType];
}
else if (expectedTypes.IsBsonArray)
{

Loading…
Cancel
Save