I have a Service Factory with a Generic method GetService
. Based on what I pass for T
it gets me a service for that particular class.
Now I have a method, which uses multiple of these services and I need to stub all of them. Ex: GetService<Coffee> , GetService<Tea>
.
mockrepo.Stub(x => x.GetService<Coffee>().Expect(c => c.RetrieveList(coffeeCollection)).IgnoreArguments());
mockrepo.Stub(x => x.GetService<Tea>().Retrieve(1)).Return(testrefDataRefEle1);
In the above code, on the second stub I get error "Object reference not set to an instance of an object."
You can't do a recursive mock like that in Rhino.Mocks. You'll have to create a stub for whatever object has the
Retrieve
method and set that up to returntestrefDataRefEle1
. Then set up the stub ofGetService<Tea>
to return the other mocked object.