public void Fork_should_return_expected_result() { var coreServerSession = new CoreServerSession(); var options = new ClientSessionOptions(); var coreSession = new CoreSession(coreServerSession, options.ToCore()); var coreSessionHandle = new CoreSessionHandle(coreSession); var subject = CreateSubject(coreSession: coreSessionHandle); coreSessionHandle.ReferenceCount().Should().Be(1); var result = subject.Fork(); result.Client.Should().BeSameAs(subject.Client); result.Options.Should().BeSameAs(subject.Options); result.WrappedCoreSession.Should().NotBeSameAs(subject.WrappedCoreSession); var coreSessionHandle1 = (CoreSessionHandle)subject.WrappedCoreSession; var coreSessionHandle2 = (CoreSessionHandle)result.WrappedCoreSession; coreSessionHandle2.Wrapped.Should().BeSameAs(coreSessionHandle1.Wrapped); coreSessionHandle.ReferenceCount().Should().Be(2); }
public void Fork_should_return_expected_result() { var cluster = Mock.Of <ICluster>(); var coreServerSession = new CoreServerSession(); var options = new ClientSessionOptions(); #pragma warning disable CS0618 // Type or member is obsolete var coreSession = new CoreSession(cluster, coreServerSession, options.ToCore()); #pragma warning restore CS0618 // Type or member is obsolete var coreSessionHandle = new CoreSessionHandle(coreSession); var subject = CreateSubject(coreSession: coreSessionHandle); coreSessionHandle.ReferenceCount().Should().Be(1); var result = subject.Fork(); result.Client.Should().BeSameAs(subject.Client); result.Options.Should().BeSameAs(subject.Options); result.WrappedCoreSession.Should().NotBeSameAs(subject.WrappedCoreSession); var coreSessionHandle1 = (CoreSessionHandle)subject.WrappedCoreSession; var coreSessionHandle2 = (CoreSessionHandle)result.WrappedCoreSession; coreSessionHandle2.Wrapped.Should().BeSameAs(coreSessionHandle1.Wrapped); coreSessionHandle.ReferenceCount().Should().Be(2); }
// NOTE(rkm 2020-03-10) We don't actually implement transaction rollback as we only need to be able to start with a fresh collection for each test public override IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = new CancellationToken()) => MockSessionHandle.Object;
public Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(Task.FromResult(StartSession(options, cancellationToken))); }
public INMClientSessionHandle(IMongoClient client) { Client = client; Options = new ClientSessionOptions { }; }
public Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(wrapped.StartSessionAsync(options, cancellationToken)); }
private IClientSessionHandle CreateSession(BsonDocument entity, Dictionary <string, DisposableMongoClient> clients) { IMongoClient client = null; ClientSessionOptions options = null; foreach (var element in entity) { switch (element.Name) { case "id": // handled on higher level break; case "client": var clientId = element.Value.AsString; client = clients[clientId]; break; case "sessionOptions": options = new ClientSessionOptions(); foreach (var option in element.Value.AsBsonDocument) { switch (option.Name) { case "snapshot": options.Snapshot = option.Value.ToBoolean(); break; case "causalConsistency": options.CausalConsistency = option.Value.ToBoolean(); break; case "defaultTransactionOptions": ReadConcern readConcern = null; ReadPreference readPreference = null; WriteConcern writeConcern = null; foreach (var transactionOption in option.Value.AsBsonDocument) { switch (transactionOption.Name) { case "readConcern": readConcern = ReadConcern.FromBsonDocument(transactionOption.Value.AsBsonDocument); break; case "readPreference": readPreference = ReadPreference.FromBsonDocument(transactionOption.Value.AsBsonDocument); break; case "writeConcern": writeConcern = WriteConcern.FromBsonDocument(transactionOption.Value.AsBsonDocument); break; default: throw new FormatException($"Invalid session transaction option: '{transactionOption.Name}'."); } } options.DefaultTransactionOptions = new TransactionOptions(readConcern, readPreference, writeConcern); break; default: throw new FormatException($"Invalid session option argument name: '{option.Name}'."); } } break; default: throw new FormatException($"Invalid session argument name: '{element.Name}'."); } } var session = client.StartSession(options); return(session); }
public Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { return(((IMongoClient)Client).StartSessionAsync(options, cancellationToken)); }
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) => _mongoClient.StartSession(options, cancellationToken);
public Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { return(Task.FromResult <IClientSessionHandle>(new INMClientSessionHandle(this))); }
/// <summary> /// Gets a transaction context/scope for the current instance's database /// </summary> /// <param name="options">Client session options (not required)</param> public Transaction Transaction(ClientSessionOptions options = null) { return(new Transaction(DatabaseName(), options)); }
/// <summary> /// Starts a client session. /// </summary> /// <param name="options">The <see cref="ClientSessionOptions" />.</param> /// <param name="cancellationToken">The <see cref="CancellationToken" />.</param> /// <returns>The <see cref="IClientSessionHandle" />.</returns> public IClientSessionHandle StartSession(ClientSessionOptions options = default, CancellationToken cancellationToken = default) => MongoClient.StartSession(options, cancellationToken);
/// <summary> /// Instantiates and begins a transaction. /// </summary> /// <param name="database">The name of the database to use for this transaction. default db is used if not specified</param> /// <param name="options">Client session options for this transaction</param> /// <param name="modifiedBy">An optional ModifiedBy instance. /// When supplied, all save/update operations performed via this DBContext instance will set the value on entities that has a property of type ModifiedBy. /// You can inherit from the ModifiedBy class and add your own properties to it. /// Only one ModifiedBy property is allowed on a single entity type.</param> public Transaction(string database = default, ClientSessionOptions options = null, ModifiedBy modifiedBy = null) { Session = DB.Database(database).Client.StartSession(options); Session.StartTransaction(); ModifiedBy = modifiedBy; }
public Task <IClientSessionHandle> initTransactionAsync(ClientSessionOptions options = null) { return(mService.client.StartSessionAsync(options)); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { return(await client.StartSessionAsync(options, cancellationToken)); }
/// <summary> /// Instantiates and begins a transaction. /// </summary> /// <param name="options">Client session options for this transaction</param> public Transaction(ClientSessionOptions options = null) { client = DB.GetClient(); Session = client.StartSession(options); Session.StartTransaction(); }
public void constructor_should_initialize_instance() { var result = new ClientSessionOptions(); result.CausalConsistency.Should().NotHaveValue(); }
public virtual Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException();
public Task <IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) => _mongoClient.StartSessionAsync(options, cancellationToken);
public static IClientSessionHandle Get(IMongoClient client, ClientSessionOptions options, double expiringInSeconds) { return(AsyncHelper.RunSync(() => GetAsync(client, options, expiringInSeconds))); }
/// <summary> /// Gets a transaction context/scope for a given database or the default database if not specified. /// </summary> /// <param name="database">The name of the database which this transaction is for (not required)</param> /// <param name="options">Client session options (not required)</param> public static Transaction Transaction(string database = default, ClientSessionOptions options = null) { return(new Transaction(database, options)); }
/// <summary> /// Gets a transaction context/scope for a given entity type's database /// </summary> /// <typeparam name="T">The entity type to determine the database from for the transaction</typeparam> /// <param name="options">Client session options (not required)</param> public static Transaction Transaction <T>(ClientSessionOptions options = null) where T : IEntity { return(new Transaction(DatabaseName <T>(), options)); }
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(wrapped.StartSession(options, cancellationToken)); }
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(new FakeClientSessionHandle(this)); }
/// <summary> /// Instantiates and begins a transaction. /// </summary> /// <param name="database">The name of the database to use for this transaction. default db is used if not specified</param> /// <param name="options">Client session options for this transaction</param> public Transaction(string database = default, ClientSessionOptions options = null) { client = DB.Database(database).Client; Session = client.StartSession(options); Session.StartTransaction(); }
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { throw new System.NotImplementedException(); }