如何使用 Rhino 存根返回带有 ref 参数的 void 的方法

发布于 2025-01-05 21:14:03 字数 620 浏览 8 评论 0原文

如果方法返回 void,我找不到使用 ref 参数对方法进行存根的方法,如下例所示:

public interface Interface1 {
    void Method1(ref int i);
}

public class Class1 {
    static public void Main() {
    MockRepository mockRepository = new MockRepository();
    Interface1 interface1 = mockRepository.Stub<Interface1>();
    int i = 1;
    //SetupResult.For(interface1.Method1(ref i)).OutRef(1);  Can't compile
    interface1.Method1(ref i);
    LastCall.Repeat.Any();
    mockRepository.ReplayAll();
    int j = 0;
    interface1.Method1(ref j);
    if(j == 1) Console.WriteLine("OK");
}

你有什么想法吗?

谢谢, 斯泰尼奥

I can't find a way to stub methods with ref arguments if they return void, as in the following example:

public interface Interface1 {
    void Method1(ref int i);
}

public class Class1 {
    static public void Main() {
    MockRepository mockRepository = new MockRepository();
    Interface1 interface1 = mockRepository.Stub<Interface1>();
    int i = 1;
    //SetupResult.For(interface1.Method1(ref i)).OutRef(1);  Can't compile
    interface1.Method1(ref i);
    LastCall.Repeat.Any();
    mockRepository.ReplayAll();
    int j = 0;
    interface1.Method1(ref j);
    if(j == 1) Console.WriteLine("OK");
}

Do you have any idea?

Thanks,
Stenio

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

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

发布评论

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

评论(1

烏雲後面有陽光 2025-01-12 21:14:03

Rhino Mocks 3.5 有一个新的约束接口,替换了 .OutRef() 等。请参阅文档

Interface1 interface1 = MockRepository.GenerateStub<Interface1>();
int i = 1;
interface1.Stub(x => x.Method1(ref Arg<int>.Ref(Is.Anything(), i).Dummy);
int j = 0;
interface1.Method1(ref j);
if (j == 1) Console.WriteLine("OK");

Rhino Mocks 3.5 has a new interface for constraints, replacing .OutRef() and others. See the documentation:

Interface1 interface1 = MockRepository.GenerateStub<Interface1>();
int i = 1;
interface1.Stub(x => x.Method1(ref Arg<int>.Ref(Is.Anything(), i).Dummy);
int j = 0;
interface1.Method1(ref j);
if (j == 1) Console.WriteLine("OK");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文