1
+ /* Copyright 2010-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 System . Threading . Tasks ;
17
+ using FluentAssertions ;
18
+ using MongoDB . Bson ;
19
+ using MongoDB . Driver . Core . Clusters ;
20
+ using MongoDB . Driver . Core . TestHelpers . Logging ;
21
+ using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
22
+ using MongoDB . TestHelpers . XunitExtensions ;
23
+ using Xunit ;
24
+ using Xunit . Abstractions ;
25
+
26
+ namespace MongoDB . Driver . Tests . Specifications . transactions
27
+ {
28
+ [ Trait ( "Category" , "Integration" ) ]
29
+ public class TransactionsProseTests : LoggableTestClass
30
+ {
31
+ private const string CollectionName = "txn-test-col" ;
32
+ private const string DatabaseName = "txn-test" ;
33
+
34
+ public TransactionsProseTests ( ITestOutputHelper output ) : base ( output )
35
+ {
36
+ }
37
+
38
+ // https://github.com/mongodb/specifications/blob/fc7996db26d0ea92091a5034c6acb287ef7282fe/source/transactions/tests/README.md#10-write-concern-not-inherited-from-collection-object-inside-transaction
39
+ [ Theory ]
40
+ [ ParameterAttributeData ]
41
+ public async Task Ensure_write_concern_is_not_inherited_from_collection_object_inside_transaction ( [ Values ( false , true ) ] bool async )
42
+ {
43
+ RequireServer . Check ( ) . ClusterTypes ( ClusterType . LoadBalanced , ClusterType . ReplicaSet , ClusterType . Sharded ) ;
44
+
45
+ using var client = DriverTestConfiguration . CreateMongoClient ( ) ;
46
+ var database = client . GetDatabase ( DatabaseName ) . WithWriteConcern ( WriteConcern . WMajority ) ;
47
+ database . DropCollection ( CollectionName ) ;
48
+
49
+ var collection = client . GetDatabase ( DatabaseName ) . GetCollection < BsonDocument > ( CollectionName )
50
+ . WithWriteConcern ( WriteConcern . Unacknowledged ) ;
51
+
52
+ using ( var session = client . StartSession ( ) )
53
+ {
54
+ session . StartTransaction ( ) ;
55
+
56
+ if ( async)
57
+ {
58
+ await collection . InsertOneAsync ( new BsonDocument ( "n" , 1 ) ) ;
59
+ await session . CommitTransactionAsync ( ) ;
60
+ }
61
+ else
62
+ {
63
+ collection . InsertOne ( new BsonDocument ( "n" , 1 ) ) ;
64
+ session. CommitTransaction ( ) ;
65
+ }
66
+ }
67
+
68
+ collection . Find ( new BsonDocument ( "n" , 1 ) ) . First ( ) . Should ( ) . NotBeNull ( ) . And . Subject [ "n" ] . AsInt32 . Should ( ) . Be ( 1 ) ;
69
+ }
70
+ }
71
+ }
0 commit comments