This is a migrated thread and some comments may be shown as answers.

How can I verify the order of method calls?

2 Answers 33 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 11 May 2011, 03:19 PM
Hi,

I am new to mocking and started looking at JustMock. But I can't seem to figure out how I can verify the order of method calls.

For an example to assert that OnStart() was called exactly once before OnStop() was called exactly once on my mock object.

Is this possible?

Sincerely, Peter

2 Answers, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 18 May 2011, 02:32 PM
Hi Peter,

Thanks again for bringing up the question. However if want to know the order in which methods are executed, currently you can achieve this only by using the DoInstead modifier. Like in the following way:


[TestMethod]
public void ShouldAssertTheOrderInWhileMethodsAreExecuted()
{
    var foo = Mock.Create<IFoo>();
    IDictionary<int, int> calls = new Dictionary<int, int>();
    int executed = 0;
    Mock.Arrange(() => foo.Submit()).DoInstead(() => calls.Add(0, executed++));
    Mock.Arrange(() => foo.Echo()).DoInstead(() => calls.Add(1, executed++));
    foo.Submit();
    foo.Echo();
    foreach (var key in calls.Keys)
    {
        Assert.AreEqual(key, calls[key]);
    }
}

In addition, we are also planning to  provide a handy way of doing it during Mock.Assert()  and hopefully it will be ready by next release.

Finally, please feel free to write us back for any further questions or issues.

Kind Regards,
Ricky
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Peter
Top achievements
Rank 1
answered on 19 May 2011, 08:50 AM
Thanks,

I was hoping there was a built-in way to do this in a simpler manner, but this approach will work for now. Looking forward to a built-in feature providing this through Mock.Assert in the future.

Thank you for your reply!

Regards,
Peter.
Tags
General Discussions
Asked by
Peter
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Peter
Top achievements
Rank 1
Share this question
or