Пример #1
0
        public async Task NativeTransaction_WithoutMaxRetries_ShouldRetryUntilSuccessful()
        {
            var throwingDummy = new ThrowingDummy(4);
            var repo          = _mongoClient.GetRepository <MyStandaloneEntity>();

            await repo.WithTransactionAsync(async() =>
            {
                throwingDummy.TryMe();
                await repo.InsertAsync(new MyStandaloneEntity("test", new SharedClass("test")));
            }, maxRetries : 0);

            var allSaved = await _mongoClient.GetRepository <MyStandaloneEntity>().GetAll().ToListAsync();

            allSaved.Should().HaveCount(1);
        }
Пример #2
0
        public async Task TransactionScope_WithMaxRetries_ShouldRetryUntilMaxRetriesReached()
        {
            var throwingDummy = new ThrowingDummy(5);
            var repo          = _mongoClient.GetRepository <MyStandaloneEntity>();

            await Assert.ThrowsAsync <MongoException>(async() =>
            {
                await repo.WithTransactionAsync(async() =>
                {
                    throwingDummy.TryMe();
                    await repo.InsertAsync(new MyStandaloneEntity("test", new SharedClass("test")));
                }, TransactionType.TransactionScope, maxRetries: 3);
            });

            var allSaved = await _mongoClient.GetRepository <MyStandaloneEntity>().GetAll().ToListAsync();

            allSaved.Should().BeEmpty();
        }