简体   繁体   English

如何在单元测试中使用内存 Sqlite 忽略嵌套事务?

[英]How to ignore nested transactions using in-memory Sqlite on Unit Tests?

I am using AspNetZero/ AspNetBoilerplate to do some automated tests and I configured my Module to not disable transactions我正在使用 AspNetZero/AspNetBoilerplate 进行一些自动化测试,并将我的模块配置为不禁用事务

    Configuration.UnitOfWork.IsTransactional = false;

But it is not working and I am having the following message:但它不起作用,我收到以下消息:

Configuration.UnitOfWork.IsTransactional = false;

My test is calling the following method:我的测试正在调用以下方法:

   UnitOfWork(TransactionScopeOption.Suppress)]
   public virtual async Task<Guid> CreateAsync(CreateEntryRequest input) 
   {
        // Some code here ...

       
   }

Did I miss any setting?我错过了任何设置吗?

[UnitOfWork(isTransactional: false)]
public GetTasksOutput GetTasks(GetTasksInput input)
{
    var tasks = _taskRepository.GetAllWithPeople(input.AssignedPersonId, input.State);
    return new GetTasksOutput
            {
                Tasks = Mapper.Map<List<TaskDto>>(tasks)
            };
}

https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#non-transactional-unit-of-work https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#non-transactional-unit-of-work

I ended up with this solution:我最终得到了这个解决方案:

public virtual async Task<Guid> CreateAsync(CreateEntryRequest input)
{
  using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
  {
     // Some code here ...
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制内存中的SQLite数据库以使单元测试更快 - Copy in-memory SQLite Database to make unit tests faster 使用nhibernate和内存中的sqlite db进行单元测试设置有什么问题? - What is wrong with this set up for unit tests using nhibernate and an in-memory sqlite db? 使用带有事务的内存数据库进行单元测试时,如何抑制 InMemoryEventId.TransactionIgnoredWarning? - How to suppress InMemoryEventId.TransactionIgnoredWarning when unit testing with in-memory database with transactions? 使用Visual Studio Team Services通过内存中的SQL数据库运行单元/集成测试 - Running Unit / Integration tests through an in-memory SQL database using Visual Studio Team Services 在内存中模拟LinqToSql存储库以用于单元测试 - Mocking a LinqToSql repository in-memory for use in unit tests 在 Docker 容器中运行 SQL Lite 内存单元测试时出错 - Error Running SQL Lite In-Memory Unit Tests in Docker Container 如何使用EF 6处理内存中实体对单元测试类/服务的限制 - How to handle limitation of in-memory entities to Unit Test class/service which is using EF 6 如何在Mono中使用Sqlite将基于磁盘的数据库加载到内存数据库中? - How to load a disk-based database to in-memory database using Sqlite in Mono? 是否可以使用SQLite.Net-PCL创建内存数据库? - Is it possible to create an In-memory database using SQLite.Net-PCL? 内存中的SQLite和数据库正在消失 - In-memory SQLite and database disappearing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM