tags:

views:

17

answers:

1
var fakeRoles = MockRepository.GenerateStub < IDictionary<PermissionLevel, string>>();
        fakeRoles[PermissionLevel.Developer] = "Developer";
        fakeRoles[PermissionLevel.DeveloperManager] = "Developer Manager";

This is specific to what that method happens to be calling, and is irrelevant for the sake of my unit test. I'd rather do this:

fakeRoles.Stub(r => r[PermissionLevel.None]).IgnoreArguments().Return("Developer");

But I get an exception telling me to set the properties directly. Is there a way to tell rhino to just return the same value for any key given to this stub IDictionary?

+2  A: 

What you are trying to do is not a stub (in RhinoMock's understanding), you have to create a mock:

var fakeRoles = MockRepository.GenerateMock < IDictionary<PermissionLevel, string>>();
fakeRoles.Expect(r => r[PermissionLevel.None]).IgnoreArguments().Return("Developer");
Grzenio
+1 this works, but why is this called a mock? because it fakes behavior of some sort?
Maslow
Hi @Maslow, in RhinoMocks a stub is something very specific - an object that has empty methods returning null and "normal" properties (they return what you assign to them). If you need more logic, you have to create a mock. Essentially its just naming convention.
Grzenio