使用 Moq 模拟 nHibernate QueryOver [英] Mocking out nHibernate QueryOver with Moq

查看:27
本文介绍了使用 Moq 模拟 nHibernate QueryOver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试时,以下行失败,引用为空:

The following line fails with a null reference, when testing:

var awards = _session.QueryOver<Body>().Where(x => x.BusinessId == (int)business).List();

我的测试是这样的:

var mockQueryOver = new Mock<IQueryOver<Body, Body>>();
mockQueryOver.Setup(q => q.List()).Returns(new List<Body> {_awardingBody});
_mockSession.Setup(c => c.QueryOver<Body>()).Returns((mockQueryOver.Object));
_mockCommandRunner = new Mock<ICommandRunner>();
_generator = new CertificateGeneratorForOpenSSLCommandLine(_mockSession.Object, _mockCommandRunner.Object, _mockDirectory.Object, _mockFile.Object, _mockConfig.Object); 

老实说,我在黑暗中四处游荡 - 我对 nHibernate 和 Moq 比较陌生,所以我不太确定要通过谷歌搜索什么来获得正确的信息.

To be honest I'm flailing around in the dark here - I'm relatively new to nHibernate and Moq, so I'm not very sure what to google to get the right information.

推荐答案

我觉得上面的代码不对.AFAIK QueryOver 是 ISession 接口上的扩展方法,您不能像那样模拟扩展方法(至少不能使用传统的模拟工具,如 Moq 或 RhinoMocks).

I don't think the above code is right. AFAIK QueryOver is an extension method on ISession interface and you can not Mock extensions method like that (at least not with conventional Mocking tools like Moq or RhinoMocks).

这篇关于使用 Moq 模拟 nHibernate QueryOver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆