Open Closed

Regarding Unit test issue #2176


User avatar
0
ChetanKumbhar created

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:"
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will provide a solution, please wait a moment.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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));
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on October 05, 2026, 11:32
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.