I'm not following...

It does return the value it is told, one you exit record mode and place the
MockRepository in replay mode.

I'm not saying there isn't something fishy here, but I need some more
explanation.

Tim

On Mon, Oct 5, 2009 at 11:29 AM, Scott White <[email protected]>wrote:

>
> Okay I think I understand that part however why is Rhino Mocks
> automatically proxying my object if it has Virtual properties and then
> throwing an exception?  Also Shouldn't it always return the value that
> it's told?  Here in this scenerio it is not.
>
> On Oct 5, 10:45 am, Tim Barcz <[email protected]> wrote:
> > No bug here that is the expected behavior
> >
> > On 10/5/09, Alex McMahon <[email protected]> wrote:
> >
> >
> >
> >
> >
> > > I see why it is happening now. When you use a MockRepository instance
> the
> > > repository is created in record mode, therefore you could get your
> version
> > > to work by adding mocks.ReplayAll() after you setup your stubbed
> response.
> >
> > > When you use the static method it automatically puts the repository
> into
> > > replay mode.
> >
> > > I think this basically comes down to a slight mixing of AAA and
> > > record/replay syntax.
> >
> > > I'd say it's not really a bug
> >
> > > 2009/10/5 Scott White <[email protected]>
> >
> > >> Good work around.  I think maybe this is a bug in Rhino Mocks?
> >
> > >> If nobody has a better explanation then I'll add it to GitHub here:
> > >>http://github.com/ayende/rhino-mocks/issues
> >
> > >> Thanks,
> > >> Scott
> >
> > >> On Oct 5, 8:59 am, Alex McMahon <[email protected]> wrote:
> > >> > I wont pretend to understand why... but you can fix the test by not
> > >> creating
> > >> > an instance of MockRepository, instead use static method
> > >> > MockRepository.GenerateStub<IDogDao>()... Once I did that it fixed
> the
> > >> test.
> >
> > >> > Perhaps someone with better knowledge of the internals can explain
> why
> > >> this
> > >> > is happening. I can't remember what the difference between the
> static
> > >> > and
> > >> > instance methods is... It sort of sounds like a problem with
> > >> > RecursiveMocking
> >
> > >> > 2009/10/5 Scott White <[email protected]>
> >
> > >> > > Below code reproduces the bug precisely:
> >
> > >> > >    public class Dog
> > >> > >    {
> > >> > >        public virtual int Speed { get; set; }
> > >> > >        public virtual bool Active { get; set; }
> > >> > >    }
> >
> > >> > >    public interface IDogDao
> > >> > >    {
> > >> > >        Dog GetDog();
> > >> > >    }
> >
> > >> > >    public class DogDao : IDogDao
> > >> > >    {
> > >> > >        public Dog GetDog() { throw new NotImplementedException();
> }
> > >> > >    }
> >
> > >> > >    public class MyService
> > >> > >    {
> > >> > >        public IDogDao DogDao { get; set; }
> >
> > >> > >        public void Manipulate()
> > >> > >        {
> > >> > >            Dog dog = DogDao.GetDog();
> > >> > >            if (dog.Active)
> > >> > >            {
> > >> > >                dog.Speed++;
> > >> > >            }
> > >> > >            else
> > >> > >            {
> > >> > >                dog.Speed = 0;
> > >> > >            }
> > >> > >        }
> > >> > >    }
> >
> > >> > >    public class MyService_test
> > >> > >    {
> > >> > >        [Test]
> > >> > >        public void Manipulate_active_dog()
> > >> > >        {
> > >> > >            var dog = new Dog() {Active = true, Speed = 1};
> > >> > >            var mocks = new MockRepository();
> > >> > >            var dao = mocks.Stub<IDogDao>();
> > >> > >            dao.Stub(x => x.GetDog()).Return(dog);
> > >> > >            MyService svc = new MyService() {DogDao = dao};
> > >> > >            svc.Manipulate();
> > >> > >            Assert.AreEqual(2, dog.Speed);
> > >> > >        }
> > >> > >    }
> >
> > >> > > If I take the Virtual off of my Dog class then it doesn't throw an
> > >> > > exception but my test fails because Rhino Mocks is sending a new
> Dog
> > >> > > object with default values (not the values I set).
> >
> > >> > > On Oct 4, 6:05 pm, Tim Barcz <[email protected]> wrote:
> > >> > > > Please post the failing code/test (that always helps).
> >
> > >> > > > Tim
> >
> > >> > > > On Sun, Oct 4, 2009 at 6:03 PM, Scott White <
> [email protected]
> >
> > >> > > wrote:
> >
> > >> > > > > I was migrating some of my R&P methods into stubs but one of
> them
> > >> > > > > I
> > >> > > > > could not convert over.  This I think is because the return
> value
> > >> is a
> > >> > > > > class with all virtual properties and Rhino Mocks seems to be
> > >> proxying
> > >> > > > > it and not returning the values that I set.
> >
> > >> > > > > dao.Stub(x => x.FindByUser(user.GetType(),
> user.Username)).Return
> > >> > > > > (user); // dao.Expect has same behavior
> >
> > >> > > > > later in my test:
> >
> > >> > > > > service.Authenticate(..)
> >
> > >> > > > > This service calls the dao and takes the user object and
> > >> maniuplates
> > >> > > > > it if necessary.  Problem with this mechanism is that I'm
> getting
> > >> an
> > >> > > > > exception
> >
> > >> > > > > Previous method 'AppUser.get_Active();' requires a return
> value or
> > >> an
> > >> > > > > exception to throw.
> >
> > >> > > > > On a check of the Active flag within my Authenticate function.
> > >> > > > > For
> > >> > > > > the time being I've reverted back to recording this
> expectation.
> > >>  Any
> > >> > > > > idea why Rhino Mocks is proxying my user object that is being
> > >> returned
> > >> > > > > or how to prevent it from doing so?
> >
> > >> > > > --
> > >> > > > Tim Barcz
> > >> > > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://
> > >> > >www.twitter.com/timbarcz
> >
> > --
> > Sent from my mobile device
> >
> > Tim Barcz
> > Microsoft C# MVP
> > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://
> www.twitter.com/timbarcz
> >
>


-- 
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

--~--~---------~--~----~------------~-------~--~----~
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