public async Task OperationsOutsideTransactionsAreUnaffected()
        {
            var mary1 = new DummyEntity("Mary1");
            var mary2 = new DummyEntity("Mary2");
            var mary3 = new DummyEntity("Mary3");
            var mary4 = new DummyEntity("Mary4");
            var repo  = _mongoClient.GetRepository <DummyEntity>("tenant_a");

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                //repo.EnlistWithCurrentTransactionScope();
                await repo.InsertAsync(mary1);
            }

            await repo.InsertAsync(mary2);

            using (var transaction = repo.StartTransaction())
            {
                await repo.InsertAsync(mary3);
            }

            await repo.InsertAsync(mary4);

            var allSaved = await repo.GetAll().ToListAsync();

            allSaved.Should().HaveCount(2).And.OnlyContain(x => x.MyProperty == "Mary2" || x.MyProperty == "Mary4");
        }
        public async Task CanRestoreSoftDeletedEntities()
        {
            var mary = new DummyEntity("Mary");
            var jane = new DummyEntity("Jane");

            await _mongoClient.GetRepository <DummyEntity>("tenant_a").InsertAsync(mary);

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var repo = _mongoClient.GetRepository <DummyEntity>("tenant_a");
                //repo.EnlistWithCurrentTransactionScope();
                await repo.DeleteByIdAsync(mary.Id, softDelete : true);

                transaction.Complete();
            }

            await Task.WhenAll(
                Task.Run(async() => {
                using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var repo = _mongoClient.GetRepository <DummyEntity>("tenant_a");
                    await Task.Delay(2);
                    //repo.EnlistWithCurrentTransactionScope();


                    await repo.RestoreSoftDeletedAsync(mary.Id);


                    transaction.Complete();
                }
            }),
                Task.Run(async() => {
                using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    await Task.Delay(1);
                    var repo = _mongoClient.GetRepository <DummyEntity>("tenant_a");

                    //repo.EnlistWithCurrentTransactionScope();

                    await _mongoClient.GetRepository <DummyEntity>("tenant_a").InsertAsync(jane);

                    transaction.Complete();
                }
            })
                );

            var allDocsInDb = await _mongoClient.GetRepository <DummyEntity>("tenant_a").GetAll().ToListAsync();

            allDocsInDb.Should().HaveCount(2).And.OnlyHaveUniqueItems();

            (await _mongoClient.GetRepository <DummyEntity>("tenant_a").ListTrashAsync()).Should().BeEmpty();
        }
        public async Task CanRestoreManyDerivedSoftDeletedAtOnce()
        {
            var mary = new DummyEntity("Mary");
            var jane = new DerivedEntity("Jane", true);

            await _mongoClient.GetRepository <DummyEntity>("tenant_a").InsertAsync(mary);

            await _mongoClient.GetRepository <DummyEntity>("tenant_a").InsertAsync(jane);

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var repo = _mongoClient.GetRepository <DummyEntity>("tenant_a");
                //repo.EnlistWithCurrentTransactionScope();
                await repo.DeleteByIdAsync(mary.Id, softDelete : true);

                await repo.DeleteByIdAsync(jane.Id, softDelete : true);

                transaction.Complete();
            }

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await Task.Delay(1);

                var repo = _mongoClient.GetRepository <DummyEntity>("tenant_a");

                //repo.EnlistWithCurrentTransactionScope();

                await _mongoClient.GetRepository <DummyEntity>("tenant_a").RestoreSoftDeletedAsync <DerivedEntity>(x => x.Entity.MyBool == true);

                transaction.Complete();
            }

            var allDocsInDb = await _mongoClient.GetRepository <DummyEntity>("tenant_a").GetAll().ToListAsync();

            allDocsInDb.Should().HaveCount(1).And.OnlyHaveUniqueItems();

            (await _mongoClient.GetRepository <DummyEntity>("tenant_a").ListTrashAsync()).Should().HaveCount(1);
        }
 public static async Task InsertDocument(DummyEntity entity, IRepository <DummyEntity> repo)
 {
     await repo.InsertAsync(entity);
 }