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");
}

何か考えはありますか?

ありがとう、ステニオ

4

1 に答える 1

1

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");
于 2012-02-17T04:08:38.583 に答える