相关疑难解决方法(0)

如何跟踪 Entity Framework Core 事件以进行集成测试?

我们需要确保基于 EF Core 的代码执行了特定类型的数据库级别的测试操作(例如,任何命令执行或任何事务提交)。

假设应该触发一个真实的数据库,我们不能通过DbContext模拟来隔离它。怎么看:

[Fact]
public async Task Test()
{
    using (var context = new FooContext())
    {
        //context-related code to produce queries and commands
    }

    Assert.True(/* any context-related transaction has been committed */);
}
Run Code Online (Sandbox Code Playgroud)

是否可以?

c# entity-framework-core .net-core

3
推荐指数
1
解决办法
1639
查看次数

标签 统计

.net-core ×1

c# ×1

entity-framework-core ×1