Starts in:
2 DAYS
7 HRS
49 MIN
36 SEC
Starts in:
2 D
7 H
49 M
36 S
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:"

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

    hi

    I will provide a solution, please wait a moment.

  • 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));
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06