Rhino Mocks LastCall syntax help, .NET
I have a problem understanding LastCall()
method.
Below is an example:
public interface IDemo
{
string Prop { get; set; }
void VoidNoArgs();
}
[TestMethod]
public void SetupResultUsingOrdered()
{
MockRepository mocks = new MockRepository();
IDemo demo = mocks.StrictMock<IDemo>();
SetupResult.For(demo.Prop).Return("Ayende");
using(mocks.Ordered())
{
demo.VoidNoArgs();
LastCall.On(demo).Repeat.Twice();
}
mocks.ReplayAll();
demo.VoidNoArgs();
for (int i = 0; i < 30; i++)
{
Assert.AreEqual("Ayende",demo.Prop);
}
demo.VoidNoArgs();
mocks.VerifyAll();
}
Am I right i开发者_开发问答n saying:
LastCall.On(demo).Repeat.Twice();
specifies that demo.VoidNoArgs()
; is called twice and the last call.
However, there is a code block between demo.VoidNoArgs()
. Does it mean that property is not counted when using LastCall
method?
Disclaimer: Non-regular Rhino-mocks user.
SetupResult does not seem to be setting an expectation in this case. Since you're using a StrictMock, you need to be explicit in setting expectations on every call made on the mock.
If you want the test to
- check on only
two calls on VoidNoArgs and not anything else
: Comment the SetupResult line. - check seq -
VoidNoArgs > Prop.get > VoidNoArgs
.
using (mocks.Ordered())
{
demo.VoidNoArgs();
Expect.On(demo).Call(demo.Prop).Return("Ayende"); // fails unless you use .Repeat.Times(30) or make just one call.
demo.VoidNoArgs();
精彩评论