简体   繁体   English

可以使用Moles创建密封类吗?

[英]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 (数据上下文),但是UsersTable<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? 有人对此有经验吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM