使用 Moq 中的 Delegate 参数验证方法

发布于 2024-08-28 12:07:43 字数 405 浏览 3 评论 0原文

在我的单元测试中使用 Moq 生成存根和模拟,我想验证是否调用了采用 Delegate 参数的方法。我不关心提供的特定 Delegate 参数,我只想确保该方法确实被调用。该方法如下所示:

public interface IInvokerProxy{
    void Invoke(Delegate method);
    ...
}

在我的测试中,我想做这样的事情:

invokerProxyMock.Verify( proxy => proxy.Invoke( It.IsAny<Delegate>));

目前它给我一个错误参数'1':无法从'方法组'转换为'System.Delegate'。有谁知道这是否可能?

Using Moq for generation of Stubs and Mocks in my unit tests, I have a case where I want to Verify that a method that takes a Delegate parameter is called. I don't care about the particular Delegate parameter supplied I just want to make sure that the method is in fact called. The method looks like this:

public interface IInvokerProxy{
    void Invoke(Delegate method);
    ...
}

In my tests I would like to do something like this:

invokerProxyMock.Verify( proxy => proxy.Invoke( It.IsAny<Delegate>));

Currently it gives me an error Argument '1': cannot convert from 'method group' to 'System.Delegate'. Does anyone know if this is possible?

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

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

发布评论

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

评论(1

掩于岁月 2024-09-04 12:07:43

我相信您缺少 It.IsAny() 上的括号。

I believe you're missing the parentheses on It.IsAny<Delegate>().

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