mirror of https://github.com/abpframework/abp.git
7 changed files with 71 additions and 10 deletions
@ -1,9 +1,10 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Uow; |
|||
|
|||
public interface ITransactionApi : IDisposable |
|||
{ |
|||
Task CommitAsync(); |
|||
Task CommitAsync(CancellationToken cancellationToken = default); |
|||
} |
|||
|
|||
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.TestApp.Domain; |
|||
using Volo.Abp.Uow; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.Uow; |
|||
|
|||
public class UnitOfWork_CancellationToken_Tests : EntityFrameworkCoreTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task Should_Cancel_Test() |
|||
{ |
|||
using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin(isTransactional: true)) |
|||
{ |
|||
await Assert.ThrowsAsync<TaskCanceledException>(async () => |
|||
{ |
|||
var cst = new CancellationTokenSource(); |
|||
cst.Cancel(); |
|||
|
|||
await GetRequiredService<IBasicRepository<Person, Guid>>().InsertAsync(new Person(Guid.NewGuid(), "Adam", 42)); |
|||
|
|||
await uow.CompleteAsync(cst.Token); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.TestApp.Domain; |
|||
using Volo.Abp.TestApp.Testing; |
|||
using Volo.Abp.Uow; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.MongoDB.Uow; |
|||
|
|||
[Collection(MongoTestCollection.Name)] |
|||
public class UnitOfWork_CancellationToken_Tests : TestAppTestBase<AbpMongoDbTestModule> |
|||
{ |
|||
[Fact] |
|||
public async Task Should_Cancel_Test() |
|||
{ |
|||
using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin(isTransactional: true)) |
|||
{ |
|||
await Assert.ThrowsAsync<OperationCanceledException>(async () => |
|||
{ |
|||
var cst = new CancellationTokenSource(); |
|||
cst.Cancel(); |
|||
|
|||
await GetRequiredService<IBasicRepository<Person, Guid>>().InsertAsync(new Person(Guid.NewGuid(), "Adam", 42)); |
|||
|
|||
await uow.CompleteAsync(cst.Token); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue