chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
public override void AddUsersToRoles(string[] usernames, string[] rolenames)
BDCInterface.AddUsersToRoles("instanceName", usernames, rolenames);

How can I write a mock for BDCInterface.AddUsersToRoles?

string[] usernames = new string[] { "un1", "un2", "un3" };
string[] rolenames = new string[] { "rn1", "rn2", "rn3" };

// mock AddUsersToRoles
Action action = delegate { BDCInterface.AddUsersToRoles("instanceName", usernames, rolenames); };

// exercise
cmisRoleProvider.AddUsersToRoles(usernames, rolenames);

// verify

When it reaches to the verify line, it fails and it says that that method was not called with those arguments ...

How can I verify the input parameters?
asked by Ben (3k points)

1 Answer

0 votes

string[] usernames = new string[] { "un1", "un2", "un3" };
string[] rolenames = new string[] { "rn1", "rn2", "rn3" }; 

cmisRoleProvider.AddUsersToRoles(usernames, rolename);

Isolate.Verify.WasCalledWithExactArguments(() => BDCInterface.AddUsersToRoles("instanceName", usernames, rolenames);

This might fail because of the arrays and I think ExactArguments is by ref; and I'm sure you know more robust argument checking is coming in future version. Could check WithAnyArguments to verify this. The main thing is that static methods can't be verified if you don't first isolate certain scenario's you'll actually get a Typemock exception stating this.

There'd be a way to do this with the old natural mocks syntax but I don't remember it and I'm trying to just hold out and wait for the 'big' release with the better argument handling.
answered by boo (21.8k points)