File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
src/MongoDB.Driver.Core/Core/Bindings
tests/MongoDB.Driver.Core.Tests/Core/Bindings Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -347,9 +347,12 @@ public void StartTransaction(TransactionOptions transactionOptions = null)
347
347
348
348
var transactionNumber = AdvanceTransactionNumber ( ) ;
349
349
var effectiveTransactionOptions = GetEffectiveTransactionOptions ( transactionOptions ) ;
350
- var transaction = new CoreTransaction ( transactionNumber , effectiveTransactionOptions ) ;
350
+ if ( ! effectiveTransactionOptions . WriteConcern . IsAcknowledged )
351
+ {
352
+ throw new InvalidOperationException ( "Transactions do not support unacknowledged write concerns." ) ;
353
+ }
351
354
352
- _currentTransaction = transaction ;
355
+ _currentTransaction = new CoreTransaction ( transactionNumber , effectiveTransactionOptions ) ;
353
356
}
354
357
355
358
/// <inheritdoc />
Original file line number Diff line number Diff line change 13
13
* limitations under the License.
14
14
*/
15
15
16
+ using System ;
16
17
using System . Reflection ;
17
18
using FluentAssertions ;
18
19
using MongoDB . Bson ;
@@ -217,6 +218,19 @@ public void Dispose_should_have_expected_result(
217
218
Mock . Get ( subject . ServerSession ) . Verify ( m => m . Dispose ( ) , Times . Once ) ;
218
219
}
219
220
221
+ [ Fact ]
222
+ public void StartTransaction_should_throw_when_write_concern_is_unacknowledged ( )
223
+ {
224
+ var cluster = CoreTestConfiguration . Cluster ;
225
+ var session = cluster . StartSession ( ) ;
226
+ var transactionOptions = new TransactionOptions ( writeConcern : WriteConcern . Unacknowledged ) ;
227
+
228
+ var exception = Record . Exception ( ( ) => session . StartTransaction ( transactionOptions ) ) ;
229
+
230
+ var e = exception . Should ( ) . BeOfType < InvalidOperationException > ( ) . Subject ;
231
+ e . Message . ToLower ( ) . Should ( ) . Contain ( "transactions do not support unacknowledged write concerns" ) ;
232
+ }
233
+
220
234
[ Fact ]
221
235
public void WasUsed_should_call_serverSession ( )
222
236
{
You can’t perform that action at this time.
0 commit comments