Tim & Mikalai,

Thanks for you replies!  After reading what I wrote a day later I'm
really sorry I used such generic terms for my example ("some",
"other", etc... Yuck).

I was thinking that the Law of Demeter was coming into play here but
I'm not sure how I want to handle this.  I guess I should change the

this.someClass.PerformAction().UpdateModelWithResults(this.model);

to

this.someClass.PerformAction();
this.someClass.UpdateModel(this.model);

The reason why I'm a little hesitant to do this is because I liked the
explicitness of the interface on this.someClass.PerformAction that it
returned an implementation of some interface that just knows how to
update the model.

Well anyways, my thought of having rhinomocks just stub out the
interfaces automatically is probably not a great idea.  Maybe having
the ability to explicitly set this automatic stubbing functionality
could work but I recon it wouldn't be worth the time.

Thanks.
Gary

On Feb 6, 1:54 am, Mikalai Kardash <[email protected]> wrote:
> Hi there,
>
> I am not sure whether it is possible to stub internal classes with Rhino.
> And, actually, I am doubt it should allow us to do so.
> As I see, you need to perform tests based on the Method() function, however
> it uses some other classes while do some stuff.
>
> So, if you need to create a stub for the class containing Method() method
> you need to do two things:
> 1. make Method() virtual like this
>     public virtual void Method()
>     {
>        ... other stuff going on here.....
>        this.someClass.PerformAction().UpdateModelWithResults(this.model);
>     }
>     This will let Rhino to stub this method.
>
> 2. Generate a stub for this method as follows:
>
>    myStub.Stub(c => c.Method()).Return(somethingIReallyNeedItToReturn);
>    // This way you should not be hurt by this.someClass that sits in
> original implementation of Method() function as it will be substituted by
> Rhino.Mocks.
>
> Instead, if you need to stub internal classes or both (the one that contains
> Method() function and internal stuff) you need to create all the stubs
> yourself.
> My guess, this is because Rhino Mocks cannot guess what data should be
> passed into functions and what should be returned by methods.
>
> If, for example, this.someClass variable is being instantiated in
> constructor then you will have to write the code similar to the following:
>
>    var someClassStub = MockRepository.GenerateStub<SomeClass>();
>    someClassStub.Stub(s => s.PerformAction).Return( <something that contains
> UpdateModelWithResults function>;
>
>    var myStub = MockRepository.GenerateStub<SUT>(someClassStub);
>
> So, when you call Method() function the someClassStub stub will be called.
> But I would not recommend the second approach based on the Tim's reply.
> Hope this helps.
>
> Best Regards,
> Mik
>
> On Fri, Feb 6, 2009 at 1:02 AM, gbrunton <[email protected]> wrote:
>
> > Just wondering what your thoughts are on the following...
>
> > ... some method in a class that I will be testing ...
> > public void Method()
> > {
> >  ... other stuff going on here.....
> >  this.someClass.PerformAction().UpdateModelWithResults(this.model);
> > }
>
> > now in a test fixture somewhere...
> > [SetUp]
> > public void SetUp()
> > {
> >  this.someClass = MockRepository.GenerateStub<SomeClass>():
> > }
>
> > [Test]
> > public void TestingOtherStuffGoingOn()
> > {
> >  ... some arranging ...
>
> >  this.CreateSUT().Method();
>
> >  ... some assertions ...
> > }
>
> > Now in my TestingOtherStuffGoingOn test I could care less about the
> > someClass.PerformAction() method call because this is being testing in
> > some other method.  But I can't test the "other stuff going on here"
> > logic without stubbing out another object that contains the
> > UpdateModelWithResults() method.
>
> > Is there anyway (or would it even make sense) for rhinomocks to
> > automatically create a stub of the class that contains the
> > UpdateModelWithResults() method instead of a null value for the
> > PerformAction() method?
>
> > Thoughts?
>
> > Thanks, Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" 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/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to