How can I verify the order of method calls?

3 posts, 1 answers
  1. Peter
    Peter avatar
    2 posts
    Member since:
    Mar 2011

    Posted 11 May 2011 Link to this post


    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. Answer
    Ricky avatar
    467 posts

    Posted 18 May 2011 Link to this post

    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:

    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++));
        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,
    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
  3. DevCraft R3 2016 release webinar banner
  4. Peter
    Peter avatar
    2 posts
    Member since:
    Mar 2011

    Posted 19 May 2011 Link to this post


    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!

Back to Top