no one?
On Sep 22, 10:50 am, Vladan <[EMAIL PROTECTED]> wrote: > Actually sorry, I've expressed something wrong... > > from MethodInfo I get the type that needs to be mocked... so I can > easily create the mock itself: > > var mock = mocks.DynamicMock(methodInfo.ReturnType); > > ... now how can I assign this? > > From methodInfo I have a method to which this mock needs to be > assigned to (methodInfo.Name), if I could only do this: > > SetupResult.For(findMethodInfo).Return(findMethodReturnTypeMock); > > On Sep 22, 10:39 am, Vladan <[EMAIL PROTECTED]> wrote: > > > I have a bit of a strange situation. > > > I have an Repository implementation which is based on a fluent > > interface for defining a Find query, it looks something like this: > > > var returnedItems = repository.Find(some_ICriteria) > > .Order(some_Order) > > .Group(some_Projection_for_group) > > .All() > > > Now, when testing this I need to write for example for SetupResult the > > following tedious code: > > > var findMock = mocks.DynamicMock<FindQueryPart>(); > > var orderMock = mocks.DynamicMock<OrderQueryPart>(); > > var groupMock = mocks.DynamicMock<GroupQueryPart>(); > > var returnedItems = new List(); > > > SetupResult.For(repository.Find(some_ICriteria)).Return(findMock); > > SetupResult.For(findMock.Order(some_Order)).Return(orderMock); > > SetupResult.For(orderMock.Group(some_Projection_for_group)).Return(groupMock); > > SetupResult.For(groupMock.All()).Return(returnedItems); > > > As you can imagine, for a single query call this is alot of code, and > > somehow I feel it smells (I need this amount of code because each step > > in the fluent interface above returns a different object via interface > > (e.g. IFindQueryPart). > > > One important thing is that the SetupResult must chain the methods in > > exactly the way they've been chained in the call (for example Order > > must be chained to Group and not vice versa). > > > Now to aid this, I've written a Lambda expression inspector (simple > > stuff) which call looks like this: > > > MockFromLambda(repository => repository.Find(some_ICriteria) > > > > .Order(some_Order) > > > > .Group(some_Projection_for_group) > > .All()); > > > And it is able to return to me a MethodInfo object for each call in > > the chain (Find call, Order call, Group call and All call). > > > My question is now... how can I generate a DynamicMock from the > > information in that MethodInfo? and after that feed that to the > > SetupResult? > > > The idea would be to dynamically generate the chain of mocks from the > > Lambda expression and chain them all together? > > > Any ideas anyone? Has anyone tried this before? > > > Thanks, > > Vladan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rhino-tools-dev?hl=en -~----------~----~----~----~------~----~------~--~---
