Skip to content

Commit 9c602c5

Browse files
committed
CSHARP-2221: Sync with latest JSON driver transaction tests.
1 parent 20b752f commit 9c602c5

File tree

11 files changed

+1094
-2
lines changed

11 files changed

+1094
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright 2018-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using FluentAssertions;
17+
18+
namespace MongoDB.Bson.TestHelpers.JsonDrivenTests
19+
{
20+
public class BsonDocumentAspectAsserter : AspectAsserter<BsonDocument>
21+
{
22+
// protected methods
23+
protected override void AssertAspect(BsonDocument actualValue, string name, BsonValue expectedValue)
24+
{
25+
actualValue[name].Should().Be(expectedValue);
26+
}
27+
}
28+
}

tests/MongoDB.Bson.TestHelpers/MongoDB.Bson.TestHelpers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<Compile Include="EqualityComparers\ReferenceEqualsEqualityComparer.cs" />
8888
<Compile Include="IO\NullBsonStream.cs" />
8989
<Compile Include="JsonDrivenTests\AspectAsserter.cs" />
90+
<Compile Include="JsonDrivenTests\BsonDocumentAspectAsserter.cs" />
9091
<Compile Include="JsonDrivenTests\JsonDrivenHelper.cs" />
9192
<Compile Include="JsonDrivenTests\JsonDrivenTestCase.cs" />
9293
<Compile Include="JsonDrivenTests\JsonDrivenTestCaseFactory.cs" />

tests/MongoDB.Driver.Tests.Dotnet/Specifications/transactions/tests/README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ For each YAML file, for each element in ``tests``:
9898
- Enter a "try" block or your programming language's closest equivalent.
9999
- If ``name`` is "startTransaction", "commitTransaction", or
100100
"abortTransaction", call the named method on ``session0`` or
101-
``session1``, depending on the "session" argument.
101+
``session1``, depending on the "session" argument.
102+
- If ``name`` is "runCommand", call the runCommand method on the database
103+
specified in the test. Pass the argument named "command" to the runCommand
104+
method. Pass ``session0`` or ``session1`` to the runCommand method, depending
105+
on which session's name is in the arguments list. If ``arguments``
106+
contains no "session", pass no explicit session to the method. If ``arguments``
107+
includes "readPreference", also pass the read preference to the runCommand
108+
method.
102109
- Otherwise, ``name`` refers to a CRUD method, such as ``insertOne``.
103110
Execute the named method on the "transactions-tests" database on the "test"
104111
collection, passing the arguments listed. Pass ``session0`` or ``session1``
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
{
2+
"database_name": "transaction-tests",
3+
"collection_name": "test",
4+
"data": [],
5+
"tests": [
6+
{
7+
"description": "run command with default read preference",
8+
"operations": [
9+
{
10+
"name": "startTransaction",
11+
"arguments": {
12+
"session": "session0"
13+
}
14+
},
15+
{
16+
"name": "runCommand",
17+
"arguments": {
18+
"command": {
19+
"insert": "test",
20+
"documents": [
21+
{
22+
"_id": 1
23+
}
24+
]
25+
},
26+
"session": "session0"
27+
},
28+
"result": {
29+
"n": 1
30+
}
31+
},
32+
{
33+
"name": "commitTransaction",
34+
"arguments": {
35+
"session": "session0"
36+
}
37+
}
38+
],
39+
"expectations": [
40+
{
41+
"command_started_event": {
42+
"command": {
43+
"insert": "test",
44+
"documents": [
45+
{
46+
"_id": 1
47+
}
48+
],
49+
"readConcern": null,
50+
"lsid": "session0",
51+
"txnNumber": {
52+
"$numberLong": "1"
53+
},
54+
"startTransaction": true,
55+
"autocommit": false,
56+
"writeConcern": null
57+
},
58+
"command_name": "insert",
59+
"database_name": "transaction-tests"
60+
}
61+
},
62+
{
63+
"command_started_event": {
64+
"command": {
65+
"commitTransaction": 1,
66+
"lsid": "session0",
67+
"txnNumber": {
68+
"$numberLong": "1"
69+
},
70+
"startTransaction": null,
71+
"autocommit": false,
72+
"writeConcern": null
73+
},
74+
"command_name": "commitTransaction",
75+
"database_name": "admin"
76+
}
77+
}
78+
]
79+
},
80+
{
81+
"description": "run command with secondary read preference in client option and primary read preference in transaction options",
82+
"clientOptions": {
83+
"readPreference": "secondary"
84+
},
85+
"operations": [
86+
{
87+
"name": "startTransaction",
88+
"arguments": {
89+
"session": "session0",
90+
"options": {
91+
"readPreference": {
92+
"mode": "Primary"
93+
}
94+
}
95+
}
96+
},
97+
{
98+
"name": "runCommand",
99+
"arguments": {
100+
"command": {
101+
"insert": "test",
102+
"documents": [
103+
{
104+
"_id": 1
105+
}
106+
]
107+
},
108+
"session": "session0"
109+
},
110+
"result": {
111+
"n": 1
112+
}
113+
},
114+
{
115+
"name": "commitTransaction",
116+
"arguments": {
117+
"session": "session0"
118+
}
119+
}
120+
],
121+
"expectations": [
122+
{
123+
"command_started_event": {
124+
"command": {
125+
"insert": "test",
126+
"documents": [
127+
{
128+
"_id": 1
129+
}
130+
],
131+
"readConcern": null,
132+
"lsid": "session0",
133+
"txnNumber": {
134+
"$numberLong": "1"
135+
},
136+
"startTransaction": true,
137+
"autocommit": false,
138+
"writeConcern": null
139+
},
140+
"command_name": "insert",
141+
"database_name": "transaction-tests"
142+
}
143+
},
144+
{
145+
"command_started_event": {
146+
"command": {
147+
"commitTransaction": 1,
148+
"lsid": "session0",
149+
"txnNumber": {
150+
"$numberLong": "1"
151+
},
152+
"startTransaction": null,
153+
"autocommit": false,
154+
"writeConcern": null
155+
},
156+
"command_name": "commitTransaction",
157+
"database_name": "admin"
158+
}
159+
}
160+
]
161+
},
162+
{
163+
"description": "run command with explicit primary read preference",
164+
"operations": [
165+
{
166+
"name": "startTransaction",
167+
"arguments": {
168+
"session": "session0"
169+
}
170+
},
171+
{
172+
"name": "runCommand",
173+
"arguments": {
174+
"command": {
175+
"insert": "test",
176+
"documents": [
177+
{
178+
"_id": 1
179+
}
180+
]
181+
},
182+
"session": "session0",
183+
"readPreference": {
184+
"mode": "Primary"
185+
}
186+
},
187+
"result": {
188+
"n": 1
189+
}
190+
},
191+
{
192+
"name": "commitTransaction",
193+
"arguments": {
194+
"session": "session0"
195+
}
196+
}
197+
],
198+
"expectations": [
199+
{
200+
"command_started_event": {
201+
"command": {
202+
"insert": "test",
203+
"documents": [
204+
{
205+
"_id": 1
206+
}
207+
],
208+
"readConcern": null,
209+
"lsid": "session0",
210+
"txnNumber": {
211+
"$numberLong": "1"
212+
},
213+
"startTransaction": true,
214+
"autocommit": false,
215+
"writeConcern": null
216+
},
217+
"command_name": "insert",
218+
"database_name": "transaction-tests"
219+
}
220+
},
221+
{
222+
"command_started_event": {
223+
"command": {
224+
"commitTransaction": 1,
225+
"lsid": "session0",
226+
"txnNumber": {
227+
"$numberLong": "1"
228+
},
229+
"startTransaction": null,
230+
"autocommit": false,
231+
"writeConcern": null
232+
},
233+
"command_name": "commitTransaction",
234+
"database_name": "admin"
235+
}
236+
}
237+
]
238+
},
239+
{
240+
"description": "run command fails with explicit secondary read preference",
241+
"operations": [
242+
{
243+
"name": "startTransaction",
244+
"arguments": {
245+
"session": "session0"
246+
}
247+
},
248+
{
249+
"name": "runCommand",
250+
"arguments": {
251+
"command": {
252+
"count": "test"
253+
},
254+
"session": "session0",
255+
"readPreference": {
256+
"mode": "Secondary"
257+
}
258+
},
259+
"result": {
260+
"errorContains": "read preference in a transaction must be primary"
261+
}
262+
}
263+
]
264+
},
265+
{
266+
"description": "run command fails with secondary read preference from transaction options",
267+
"operations": [
268+
{
269+
"name": "startTransaction",
270+
"arguments": {
271+
"session": "session0",
272+
"options": {
273+
"readPreference": {
274+
"mode": "Secondary"
275+
}
276+
}
277+
}
278+
},
279+
{
280+
"name": "runCommand",
281+
"arguments": {
282+
"command": {
283+
"count": "test"
284+
},
285+
"session": "session0"
286+
},
287+
"result": {
288+
"errorContains": "read preference in a transaction must be primary"
289+
}
290+
}
291+
]
292+
}
293+
]
294+
}

0 commit comments

Comments
 (0)