Mocking Methods Only

0 views
Skip to first unread message

Luke

unread,
Jan 30, 2008, 6:11:05 PM1/30/08
to Rhino.Mocks
I've been struggling with this for a couple hours now and for the life
of me can't figure out how to make it work.

Here's the case:
The presenter has a call
this.view.programs=RequestPrincipal.Current.GetPrograms;
The RequestPrincipal class is something that is very cumberson to mock
and etc but all it does is return a CustomTypeArray[] so I'm trying to
figure out if I can do something like this:
Expect.Call(RequestPrincipal.Current.GetPrograms).Return(dummyCustomTypeArray);

The issue that I get is "System.NullReferenceException: Object
reference not set to an instance of an object.." because
RequestPrincipal is not created anywhere. Is there another way of
doing this? Just setting up an expected call to some method on a
not-mocked object and explicitly telling it to return a result.

Thanks so much,
Luke

Adam Dymitruk

unread,
Jan 30, 2008, 6:35:30 PM1/30/08
to Rhino...@googlegroups.com
You need to set the expectation on Current, not GetPrograms.
RequestPrincipal is what you are mocking, no?

Adam

Luke

unread,
Jan 30, 2008, 6:46:52 PM1/30/08
to Rhino.Mocks
No. Mocking Request Principal has its own issues (no default
constructor and etc). I'm trying to see if there's a way to simply
say if someone calls SomeUnMockedObject.GetMeAList() if there is a way
to simply set an expectation for that call to always return
List<Whatever> SomeEmptyList without actually mocking or instantiating
the SomeUnMockedObject.

On Jan 30, 3:35 pm, "Adam Dymitruk" <adymit...@gmail.com> wrote:
> You need to set the expectation on Current, not GetPrograms.
> RequestPrincipal is what you are mocking, no?
>
> Adam
>
> On Jan 30, 2008 3:11 PM, Luke <jalm...@gmail.com> wrote:
>
>
>
>
>
> > I've been struggling with this for a couple hours now and for the life
> > of me can't figure out how to make it work.
>
> > Here's the case:
> > The presenter has a call
> > this.view.programs=RequestPrincipal.Current.GetPrograms;
> > The RequestPrincipal class is something that is very cumberson to mock
> > and etc but all it does is return a CustomTypeArray[] so I'm trying to
> > figure out if I can do something like this:
> > Expect.Call(RequestPrincipal.Current.GetPrograms).Return(dummyCustomTypeArr­ay);
>
> > The issue that I get is  "System.NullReferenceException: Object
> > reference not set to an instance of an object.." because
> > RequestPrincipal is not created anywhere. Is there another way of
> > doing this?  Just setting up an expected call to some method on a
> > not-mocked object and explicitly telling it to return a result.
>
> > Thanks so much,
> > Luke- Hide quoted text -
>
> - Show quoted text -

Shawn Neal

unread,
Jan 30, 2008, 6:49:43 PM1/30/08
to Rhino...@googlegroups.com

I would probably extract an interface somewhere and pass that instance into my presenter.  RequestPrincipal.Current looks like a service locator call which I like to avoid anyway.

Luke

unread,
Jan 30, 2008, 6:54:27 PM1/30/08
to Rhino.Mocks
Unfortunately this is not something I can do (this is a big team
project). So I was trying to find a way to test just my stuff without
having to create additional interfaces and etc.

On Jan 30, 3:49 pm, "Shawn Neal" <neal.sh...@gmail.com> wrote:
> I would probably extract an interface somewhere and pass that instance into
> my presenter.  RequestPrincipal.Current looks like a service locator call
> which I like to avoid anyway.
>
> On Jan 30, 2008 3:11 PM, Luke <jalm...@gmail.com> wrote:
>
>
>
>
>
> > I've been struggling with this for a couple hours now and for the life
> > of me can't figure out how to make it work.
>
> > Here's the case:
> > The presenter has a call
> > this.view.programs=RequestPrincipal.Current.GetPrograms;
> > The RequestPrincipal class is something that is very cumberson to mock
> > and etc but all it does is return a CustomTypeArray[] so I'm trying to
> > figure out if I can do something like this:
> > Expect.Call(RequestPrincipal.Current.GetPrograms
> > ).Return(dummyCustomTypeArray);
>
> > The issue that I get is  "System.NullReferenceException: Object
> > reference not set to an instance of an object.." because
> > RequestPrincipal is not created anywhere. Is there another way of
> > doing this?  Just setting up an expected call to some method on a
> > not-mocked object and explicitly telling it to return a result.
>
> > Thanks so much,

Adam Dymitruk

unread,
Jan 30, 2008, 7:41:16 PM1/30/08
to Rhino...@googlegroups.com
Wrap, then mock.. or make an adapter.. or resort to typemock or some
other IL weaving... I would do the former.
Reply all
Reply to author
Forward
0 new messages