Sunday 16 August 2020

Xunit Mocking methods setup with Action<> parameter

I did setup a callback method in setup with Action<> parameter as onSuccess and onFailure callback. After seamless implementation i was trying to setup moq for the same method. And i finished everything up by using following code snippet.

Method template:

void ValidateUserAccess(List<int> conpanyIds, int? userId = null, Action<List<int>> onSuccess = null, Action<List<int>> onFailure = null, bool allowPartialExecution = false);

Moq Setup:

 _mqUserService.Setup(m => m.ValidateUserAccess(
                .Callback((List<int> ids, int? userId , Action<List<int>> onSuccess , Action<List<int>> onFailure , bool isExecteall) =>
//Other stuff to validate