1

尝试使用 SQLite 进行工作正常的单元测试,但测试一些存储库是有问题的,因为它们使用事务。

对于使用 ReadCommitted 的事务,一切都很好,但是其中一些使用 ReadUncommitted 看看 System.Data.SQLite 不支持:

if ((this._defaultIsolation != IsolationLevel.Serializable) && (this._defaultIsolation != IsolationLevel.ReadCommitted))
{
        throw new NotSupportedException("Invalid Default IsolationLevel specified");
}

我想知道,是否可以拦截 Session.BeginTransaction(...) 以便我可以更改事务级别,仅用于单元测试。

更新: 我的解决方案是下载 System.Data.SQLite 的源代码并修改异常以设置默认隔离级别。我在这里写博客:

http://www.philliphaydon.com/2011/01/system-data-sqlite-isolationlevel-exception/

4

1 回答 1

0

没有简单的扩展点,没有实现ITransactionFactoryITransaction.

将调用包装起来可能更容易BeginTransaction避免在测试时使用 ReadUncommitted。

于 2010-12-31T18:21:24.817 回答