views:

21

answers:

0

I have a security rule that a newly registered user has full permissions over their own user entity. I'm using Rhino.Security and the code works fine, but I want to create a unit test to make sure the appropriate call is made to setup the permission. Here is a simplified verison of the code:

public User Register(UserRegisterTask userRegistrationTask) {
   User user = User.Create(userRegistrationTask);
   this.userRepository.Save(user);

   // Give this user permission to do operations on itself
   this.permissionsBuilderService.Allow("Domain/User")
       .For(user)
       .On(user)
       .DefaultLevel()
       .Save();

   return user;
}

I've mocked the userRepository and the permissionBuilderService but the fluent interface of the permissionBuilderService requires different objects to be returned from each method call in the chain (i.e. .Allow(...).For(...).On(...) etc). But I can't find a way to mock each of the objects in the chain.

Is there a way to test if the permissionBuilderService's Allow method is being called but ignoring the rest of the chain?

Thanks Dan