我正在使用 Linq 到 NHibernate。
我有以下测试用例:
[TestMethod]
[DeploymentItem("hibernate.cfg.xml")]
public void Category_Should_GetAllByLinq()
{
// Arrange
IRepository<Category> repo = new CategoryRepository();
//Act
IList<Category> list = repo.GetListByLinq();
//Assert
Assert.IsTrue(list.Count > 0);
}
而且我在 CategoryRepository 类中有以下代码:
public IList<Category> GetListByLinq()
{
ISession session = NHibernateHelper.OpenSession();
// When following statement is executed, How to check converted real sql query?
var query = from c in session.Linq<Category>()
select c;
return query.ToList();
}
我的问题是,一旦执行 linq to nhibernate 语句,如何检查真正转换的 sql 查询?有什么方法吗?
我知道我可以使用 SQL 探查器,但是我想在测试用例中使用 Mock 对象,所以我不想在任何与数据库相关的方法中看到它。