Exemplo n.º 1
0
        public UnitOfWorkTest()
        {
            transactionOptions = new TransactionOptions(readPreference: ReadPreference.Primary, readConcern: ReadConcern.Local, writeConcern: WriteConcern.WMajority);
            cancellationToken  = CancellationToken.None;

            clientSessionHandle = Substitute.For <IClientSessionHandle>();
            clientSessionHandle
            .WithTransactionAsync(
                Arg.Any <Func <IClientSessionHandle, CancellationToken, Task <bool> > >(),
                Arg.Any <TransactionOptions>(),
                Arg.Any <CancellationToken>())
            .Returns(true);

            clientSessionHandle
            .WithTransaction(
                Arg.Any <Func <IClientSessionHandle, CancellationToken, bool> >(),
                Arg.Any <TransactionOptions>(),
                Arg.Any <CancellationToken>())
            .Returns(true);

            mongoClient = Substitute.For <IMongoClient>();
            mongoClient.StartSessionAsync().Returns(clientSessionHandle);
            mongoClient.StartSession().Returns(clientSessionHandle);

            unitOfWork = new UnitOfWorkMongo.UnitOfWork(mongoClient, transactionOptions);
        }
Exemplo n.º 2
0
        public void Execute(Action <BsonDocument, bool, CancellationToken> assertOperationCallback, CancellationToken cancellationToken)
        {
            _session.WithTransaction(
                callback: (session, token) =>
            {
                foreach (var operationItem in _operations)
                {
                    assertOperationCallback(operationItem.AsBsonDocument, false, token);
                }

                return((object)null);
            },
                transactionOptions: _options,
                cancellationToken: cancellationToken);
        }
Exemplo n.º 3
0
 public TResult WithTransaction <TResult>(Func <IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions?transactionOptions = null, CancellationToken cancellationToken = default)
 {
     return(_sessionHandle.WithTransaction(callback, transactionOptions, cancellationToken));
 }