Best practice for verifying multiple Arrange setups

1 Answer 11 Views
API General Discussions JustMock Free Edition
Top achievements
Rank 1
Drew asked on 20 Mar 2024, 10:02 PM

In my test I am using both MockingContainer and Mock to do Automocking and create concrete mocks respectively.

At the end of my test I want to ensure all of the functions I setup via Arrange for both the MockingContainer and mocked classes were ran.

Do I need to call .AssertAll() for each mocked object and the MockingContainer or can I simply call Mock.AssertAll() to make sure all Arranged functions were executed? See example below for both approaches.

// Establish mocks
var mockedControllerContainer = new MockingContainer<SomeController>();
var mockedClass = Mock.Create<SomeClass>();

// Establish test variables
IEnumerable<SomeDomainModel> records = new List<SomeDomainModel>();

// Arrange Mocks
    .Arrange<Repository>(repo => repo.FetchRecordsWithName("name"))

    .Arrange(c => c.SomeFunction())

// Assert

// Or can I use the example below to cover all cases?


Which approach is best practice to ensure each function was called? This example only had one concrete class but other tests can have many so if I can avoid having to use .AssertAll() for each of them individutally that would be ideal.

The API documentation for Mock.AssertAll() states "Asserts all expected setups in the current context". How is this context defined?

Thank you!

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 21 Mar 2024, 11:10 AM

Hello Drew,

Thanks for raising up this interesting question. The short answer is: yes Mock.AssertAll could be safely used for verifying all expectations in your example. You can find the long version of the answer by following this article.

I hope the provided info helps. If you need further assistance do not hesitate to write us back.

Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at
API General Discussions JustMock Free Edition
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question