开发者

Can Rhino stub out a dictionary so that no matter what key is used the same value comes back?

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?


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜