Hi, I am trying to run Unit test cases, but i am getting following error.
Message: System.InvalidOperationException : SqliteConnection does not support nested transactions.
Stack Trace: SqliteConnection.BeginTransaction(IsolationLevel isolationLevel, Boolean deferred) SqliteConnection.BeginTransaction(IsolationLevel isolationLevel) SqliteConnection.BeginDbTransaction(IsolationLevel isolationLevel) DbConnection.BeginTransaction(IsolationLevel isolationLevel) RelationalConnection.BeginTransaction(IsolationLevel isolationLevel) RelationalConnection.BeginTransaction() DatabaseFacade.BeginTransaction() UnitOfWorkDbContextProvider1.CreateDbContextWithTransaction(IUnitOfWork unitOfWork) UnitOfWorkDbContextProvider1.CreateDbContext(IUnitOfWork unitOfWork) UnitOfWorkDbContextProvider1.CreateDbContext(IUnitOfWork unitOfWork, String connectionStringName, String connectionString) <44 more frames...> CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) <<GetInvoiceByStatusAsync>b__0>d.MoveNext() line 256 --- End of stack trace from previous location --- InvoiceManagementTestBase1.WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func1 action) line 33 InvoiceApplicationTests.GetInvoiceByStatusAsync() line 254 --- End of stack trace from previous location ---~~~~
what i am missing?
I have tried solution you provoided in following ticket response, but still issue not fix. https://support.abp.io/QA/Questions/1929/Regarding-Unit-test-issue#answer-759c5e2b-5867-6cd3-51ae-39ff5b099289
- ABP Framework version: v4.3.1
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:"
2 Answer(s)
-
0
hi
I will provide a solution, please wait a moment.
-
0
hi
[Dependency(ReplaceServices = true)] public class MyUnitOfWorkManager : IUnitOfWorkManager, ISingletonDependency { private readonly UnitOfWorkManager _innerUnitOfWorkManager; public MyUnitOfWorkManager(UnitOfWorkManager innerUnitOfWorkManager) { _innerUnitOfWorkManager = innerUnitOfWorkManager; } public IUnitOfWork Begin(AbpUnitOfWorkOptions options, bool requiresNew = false) { options.IsTransactional = false; return _innerUnitOfWorkManager.Begin(options, requiresNew); } public IUnitOfWork Reserve(string reservationName, bool requiresNew = false) { return _innerUnitOfWorkManager.Reserve(reservationName, requiresNew); } public void BeginReserved(string reservationName, AbpUnitOfWorkOptions options) { options.IsTransactional = false; _innerUnitOfWorkManager.BeginReserved(reservationName, options); } public bool TryBeginReserved(string reservationName, AbpUnitOfWorkOptions options) { options.IsTransactional = false; return _innerUnitOfWorkManager.TryBeginReserved(reservationName, options); } public IUnitOfWork Current => _innerUnitOfWorkManager.Current; }
public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddSingleton(typeof(UnitOfWorkManager)); }