Skip to content

Commit 5bd1d28

Browse files
author
Oleksandr Poliakov
committed
PR
1 parent 9062dd7 commit 5bd1d28

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

src/MongoDB.Driver/AggregateHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static RenderedPipelineDefinition<TResult> RenderAggregatePipeline<TDocum
2727

2828
var lastStage = renderedPipeline.Documents.LastOrDefault();
2929
var lastStageName = lastStage?.GetElement(0).Name;
30-
isAggregateToCollection = lastStage != null && (lastStageName == "$out" || lastStageName == "$merge");
30+
isAggregateToCollection = lastStageName == "$out" || lastStageName == "$merge";
3131

3232
return renderedPipeline;
3333
}

src/MongoDB.Driver/MongoClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public MongoClient(MongoClientSettings settings)
6767

6868
_cluster = _settings.ClusterSource.Get(_settings.ToClusterKey());
6969
_operationExecutor = new OperationExecutor(this);
70-
_readOperationOptions = new ReadOperationOptions(DefaultReadPreference: _settings.ReadPreference);
71-
_writeOperationOptions = new WriteOperationOptions();
70+
_readOperationOptions = new(DefaultReadPreference: _settings.ReadPreference);
71+
_writeOperationOptions = new();
7272

7373
if (settings.AutoEncryptionOptions != null)
7474
{
@@ -121,6 +121,7 @@ internal MongoClient(IOperationExecutor operationExecutor, MongoClientSettings s
121121
// internal methods
122122
internal void ConfigureAutoEncryptionMessageEncoderSettings(MessageEncoderSettings messageEncoderSettings)
123123
{
124+
ThrowIfDisposed();
124125
var autoEncryptionOptions = _settings.AutoEncryptionOptions;
125126
if (autoEncryptionOptions != null)
126127
{

src/MongoDB.Driver/MongoDatabase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ public IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCo
325325

326326
public IAsyncCursor<string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default)
327327
{
328-
var cursor = OperationExecutor.ExecuteReadOperation(CreateListCollectionNamesOperation(options),
328+
var cursor = OperationExecutor.ExecuteReadOperation(
329+
CreateListCollectionNamesOperation(options),
329330
_readOperationOptions with { DefaultReadPreference = ReadPreference.Primary },
330-
null, cancellationToken);
331+
null,
332+
cancellationToken);
331333
return new BatchTransformingAsyncCursor<BsonDocument, string>(cursor, ExtractCollectionNames);
332334
}
333335

src/MongoDB.Driver/OperationExecutor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public TResult ExecuteReadOperation<TResult>(
3737
IClientSessionHandle session,
3838
CancellationToken cancellationToken)
3939
{
40-
bool isOwnSession = session == null;
40+
var isOwnSession = session == null;
4141
session ??= StartImplicitSession(cancellationToken);
4242

4343
try
@@ -61,7 +61,7 @@ public async Task<TResult> ExecuteReadOperationAsync<TResult>(
6161
IClientSessionHandle session,
6262
CancellationToken cancellationToken)
6363
{
64-
bool isOwnSession = session == null;
64+
var isOwnSession = session == null;
6565
session ??= await StartImplicitSessionAsync(cancellationToken).ConfigureAwait(false);
6666

6767
try
@@ -85,7 +85,7 @@ public TResult ExecuteWriteOperation<TResult>(
8585
IClientSessionHandle session,
8686
CancellationToken cancellationToken)
8787
{
88-
bool isOwnSession = session == null;
88+
var isOwnSession = session == null;
8989
session ??= StartImplicitSession(cancellationToken);
9090

9191
try
@@ -108,7 +108,7 @@ public async Task<TResult> ExecuteWriteOperationAsync<TResult>(
108108
IClientSessionHandle session,
109109
CancellationToken cancellationToken)
110110
{
111-
bool isOwnSession = session == null;
111+
var isOwnSession = session == null;
112112
session ??= await StartImplicitSessionAsync(cancellationToken).ConfigureAwait(false);
113113

114114
try
@@ -151,7 +151,7 @@ private IReadWriteBindingHandle CreateReadWriteBinding(IClientSessionHandle sess
151151
private IClientSessionHandle StartImplicitSession()
152152
{
153153
var options = new ClientSessionOptions { CausalConsistency = false, Snapshot = false };
154-
ICoreSessionHandle coreSession = _client.GetClusterInternal().StartSession(options.ToCore(isImplicit: true));
154+
var coreSession = _client.GetClusterInternal().StartSession(options.ToCore(isImplicit: true));
155155
return new ClientSessionHandle(_client, options, coreSession);
156156
}
157157
}

tests/MongoDB.Driver.Tests/OperationExecutorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class OperationExecutorTests
2929
{
3030
[Theory]
3131
[ParameterAttributeData]
32-
public async Task StartImplicitSessionTests([Values(true, false)]bool isAsync)
32+
public async Task StartImplicitSession_should_call_cluster([Values(true, false)]bool isAsync)
3333
{
3434
var subject = CreateSubject(out var clusterMock, out _);
3535
if (isAsync)
@@ -46,7 +46,7 @@ public async Task StartImplicitSessionTests([Values(true, false)]bool isAsync)
4646

4747
[Theory]
4848
[MemberData(nameof(ImplicitSessionTestCases))]
49-
public async Task ExecuteReadOperationShouldStartAndDisposeImplicitSessionIfNeeded(bool shouldCreateSession, bool isAsync, IClientSessionHandle session)
49+
public async Task ExecuteReadOperation_should_start_and_dispose_implicit_session_if_needed(bool shouldCreateSession, bool isAsync, IClientSessionHandle session)
5050
{
5151
var subject = CreateSubject(out var clusterMock, out var implicitSessionMock);
5252
var readOperation = Mock.Of<IReadOperation<object>>();
@@ -63,7 +63,7 @@ await subject.ExecuteReadOperationAsync(readOperation, readOperationOptions, ses
6363

6464
[Theory]
6565
[MemberData(nameof(ImplicitSessionTestCases))]
66-
public async Task ExecuteWriteOperationShouldStartAndDisposeImplicitSessionIfNeeded(bool shouldCreateSession, bool isAsync, IClientSessionHandle session)
66+
public async Task ExecuteWriteOperation_should_start_and_dispose_implicit_session_if_needed(bool shouldCreateSession, bool isAsync, IClientSessionHandle session)
6767
{
6868
var subject = CreateSubject(out var clusterMock, out var implicitSessionMock);
6969
var writeOperation = Mock.Of<IWriteOperation<object>>();

0 commit comments

Comments
 (0)