Can I make Rhino Mocks GenerateStub or GenerateMock return a new type every time? -
i want create ilist of objects different concrete types, so:
var tasks = new list<itask>(); foreach (string taskname in tasknames) { var task = mockrepository.generatestub<itask>(); task.stub(t => t.name).return(taskname); tasks.add(task); } return tasks;
the problem each stub object same concrete type. fine, have case want test each 1 being different type. can somehow configure rhino mocks this, in case?
edit:
the "you-must-be-doing-it-wrong-crew" out in force today. since seem think need justify use-case before can take stab @ answering question, here's i'm doing:
- itask in domain model, it's part of business layer.
- i have logic in higher level (presentation) layer takes itask argument.
- the presentation layer logic executes default strategy on itask, there can special cases need use different strategy, , strategy use depends entirely upon concrete type of itask object.
- the regular strategy pattern doesn't work here because requires concrete itask objects know layer above them.
- decorators still have know concrete type of object decorate, , have applied either @ construction time (wrong layer case) or when used, leaves me same problem - applying decorator based on concrete type.
- i decided use same pattern used datatemplates (and datatype attribute) in wpf. is, given object lower layer, see if anyone's registered strategy handle type, , if so, use it. otherwise, use default strategy.
so, hope can see why need test logic. far i've had write own stub factory generates limited pool of concrete itask types. works, i'd rather let rhino mocks me.
you add itask.type
property.
the code interested in type behind interface should use property instead of calling gettype()
. in tests, becomes trivial take control of type
property returns given itask
stub.
Comments
Post a Comment