[英]Can Moles be used to create a sealed class?
I am trying to mock my Linq To SQL classes. 我正在尝试模拟我的Linq To SQL类。
I have the following code: 我有以下代码:
IQueryable<User> vUser =
(from aUser in _ctx.Users
where aUser.UserName == userName
select aUser);
Clearly while doing a unit test _ctx.Users
is null. 显然,在进行单元测试
_ctx.Users
为null。 I can mock _ctx
(the data context), but Users
is a Table<T>
and is sealed. 我可以模拟
_ctx
(数据上下文),但是Users
是Table<T>
并被密封。 So this fails: 所以这失败了:
_ctx.Users = Table<User>();
Pex talks about being able to divert any method call via the use of Moles . Pex谈到了能够通过使用Moles转移任何方法调用。
I see examples letting you override DateTime.Now(), but I can't see if this would help in my scenario. 我看到了让您覆盖DateTime.Now()的示例,但是我看不到这对我的情况是否有帮助。
Any one have experience with this? 有人对此有经验吗?
Yes it can. 是的,它可以。
See this post for more info. 有关更多信息,请参见此帖子。
http://social.msdn.microsoft.com/Forums/en-US/pex/thread/d73f730b-37df-40f9-8c62-afb76993fbbe/#86699ca1-70e6-4026-a1f9-4978e286d0a3 http://social.msdn.microsoft.com/Forums/zh-CN/pex/thread/d73f730b-37df-40f9-8c62-afb76993fbbe/#86699ca1-70e6-4026-a1f9-4978e286d0a3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.