English 中文(简体)
Rhino Mocks should BackToRecord()也明确了采用某种方法的次数?
原标题:With Rhino Mocks should BackToRecord() also clear the count of the number of times a method was called?

关于SO的许多其他问题,据指出,为了重新确定对一个模拟物体采用某种方法的次数,你可以称之为“背书”,然后是“回想”。

然而,这不利于我。 它将重新确定顽固的价值观,而不是要求采用的方法。

因此,从相关问题中推广一个实例......

public interface IFoo { string GetBar(); }
    [TestMethod]
    public void TestRhino()
    {
        var fi = MockRepository.GenerateStub<IFoo>();
        fi.Stub(x => x.GetBar()).Return("A");
        Assert.AreEqual("A", fi.GetBar());
        fi.AssertWasCalled(x=>x.GetBar(), x=>x.Repeat.Once());

        // Switch to record to clear behaviour and then back to replay
        fi.BackToRecord(BackToRecordOptions.All);
        fi.Replay();

        fi.Stub(x => x.GetBar()).Return("B");
        Assert.AreEqual("B", fi.GetBar());
        fi.AssertWasCalled(x => x.GetBar(), x => x.Repeat.Once());
    }

这最后不符合预期第1号,即实际第2号。

我要么遗漏了问题,要么根本不是为了计算方法? 如果不制造新的 mo子,是否可有任何进展?

由于我赢得了一定地位,我无法在呼吁Get Bar(Bar)()之前确定期望。

最佳回答

确实,它没有做这样的工作;这是一个不寻常的使用案例。

这里可以选择:

[TestMethod]
public void TestRhino()
{

    var getBarCount = 0;

    var fi = MockRepository.GenerateStub<IFoo>();
    fi.Stub(x => x.GetBar()).Return("A").WhenCalled(x => getBarCount++);
    Assert.AreEqual("A", fi.GetBar());
    Assert.AreEqual(1, getBarCount);

    // Switch to record to clear behaviour and then back to replay
    fi.BackToRecord(BackToRecordOptions.All);
    fi.Replay();
    getBarCount = 0;

    fi.Stub(x => x.GetBar()).Return("B").WhenCalled(x => getBarCount++);
    Assert.AreEqual("B", fi.GetBar());
    Assert.AreEqual(1, getBarCount);
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签