开发者

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

开发者 https://www.devze.com 2022-12-19 01:59 出处:网络
var fakeRoles = MockRepository.GenerateStub < IDictionary<PermissionLevel, string>>(); fakeRoles[PermissionLevel.Developer] = \"Developer\";
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

精彩评论

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

关注公众号