Hi,
 
"Get" is an extenstion method; it cannot be mocked using RhinoMocks; only 
virtual methods can be mocked. The ArgumentNullException is caused by "Get" 
in turn invoking the virtual method "Resolve", which is caught by 
RhinoMocks and made to return "null". This is then passed to 
Enumerable.Cast, which throws the ArgumentNullException..
 
The correct way of solving this is by stubbing the virtual methods, i.e., 
"Resolve" (and before that, "CreateRequest"), rather than "Get".
 
(Moq, BTW, also cannot mock extension methods. However, Moq might return a 
recursive stub rather than null when "Get" calls "Resolve", which prevents 
the ArgumentNullException from being thrown. I don't think RhinoMocks can 
be configured to return recursive stubs rather than null results on method 
calls.)
 
Best regards,
Fabian

On Wednesday, January 2, 2013 1:10:00 AM UTC+1, M wrote:

> But believe me, It is not working, It is just 3 lines of code, you can see 
> it is not working with either Stub or Expect.
>
> I think testing Ninject Kernels are painful with Rhino and that's why 
> these project exists : https://github.com/ninject/ninject.mockingkernel
>
> I used MOQ and it mocked the IKernel like a charm.
>
> Cheers
>
> On Wednesday, January 2, 2013 9:43:07 AM UTC+11, sixeyes wrote:
>>
>> I believe you also need to change Expect to Stub.
>>
>> Iain
>>
>> On 1 January 2013 22:18, M <[email protected]> wrote:
>>
>>> Sorry, Didn't work. Still getting the same exception.
>>>
>>>
>>> On Monday, December 31, 2012 7:55:30 PM UTC+11, M wrote:
>>>>
>>>> Hi
>>>>
>>>> This is the block of code that I have written to test some method. But 
>>>> it throws an exception on line 3 that "Value can not be null ".
>>>>
>>>> IDataRepository repository = 
>>>> M**ockRepository.GenerateStub<IDa**taRepository>();IKernel kernel = 
>>>> MockRepositor**y.GenerateStub<IKernel>();
>>>> kernel.Expect(k => k.Get<IData**Repository>()).Return(**repository);
>>>>
>>>>
>>>> [image: Inline image 1]
>>>>
>>>>
>>>>
>>>> What should I do ?
>>>>
>>>> Regards
>>>>
>>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Rhino.Mocks" group.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msg/rhinomocks/-/t-M9lSERsE8J.
>>>
>>> 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/rhinomocks?hl=en.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rhinomocks/-/_z6kGx7dhf8J.
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/rhinomocks?hl=en.

Reply via email to