哪些类具有 Moles 可以重定向的方法?

发布于 2024-12-21 04:07:23 字数 212 浏览 2 评论 0原文

我见过使用 Moles 重定向 DateTime.Now 的示例,但是当我尝试重定向 System.Net.Sockets.TcpClient.GetStream 时,我无法生成相应的 MTcpClient 出现在 Intellisense 上。

Moles 方法可以重定向的类数量是否有限?我是否遗漏了任何步骤?

I've seen samples using Moles to redirect DateTime.Now but when I tried to redirect System.Net.Sockets.TcpClient.GetStream I couldn't make the corresponding MTcpClient appear on Intellisense.

Is there a limited number of classes which methods Moles can redirect? Is there any step that I missed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2024-12-28 04:07:23

首先,它是 System.Net.Sockets.Moles.MTcpClient,不要忘记 Moles 命名空间。

其次,在模拟 Core.dll 时似乎有一个怪癖:以通常的方式(通过右键单击解决方案资源管理器中的引用)为此程序集添加 .moles 文件后,您需要将其修改为如下所示:

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
  <Assembly Name="System" ExportedTypes="true" ReflectionOnly="true" />
</Moles>

否则您可能会出现构建错误,如本问题中所述。

First, it's System.Net.Sockets.Moles.MTcpClient, don't forget the Moles namespace.

Second, there seems to be a quirk when mocking Core.dll: after adding the .moles file for this assembly the usual way (by right-clicking the reference in Solution Explorer) you need to modify it to look like this:

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
  <Assembly Name="System" ExportedTypes="true" ReflectionOnly="true" />
</Moles>

or else you might get build errors as described in this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文