Как заглушить метод, возвращающий void с аргументами ref с Rhino - PullRequest
0 голосов
/ 16 февраля 2012

Я не могу найти способ заглушить методы с аргументами ref, если они возвращают void, как в следующем примере:

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

У вас есть идеи?

Спасибо,Стенио

1 Ответ

1 голос
/ 17 февраля 2012

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