RhinoMocks does not let you stub methods defined on System.Object and System.MarshalByRefObject you can mock ToString only if mocked class overrides it.
On 12 Lis, 05:08, Patrick Steele <[email protected]> wrote: > Anyone have any ideas? > > -- > Patrick Steelehttp://weblogs.asp.net/psteele > > On Mon, Nov 9, 2009 at 1:41 PM, Patrick Steele <[email protected]> > wrote: > > I thought Rhino Mocks could stub/mock object.ToString(): > > >http://ayende.com/Blog/archive/2005/07/12/RhinoMocks201MinorBugFixes.... > > > But someone recently tweeted that they couldn't get it working. I > > threw together a quick test with both AAA and record/replay and I > > can't get it working either: > > > [TestFixture] > > public class Tests > > { > > [Test] > > public void StubToString_AAA() > > { > > var obj = MockRepository.GenerateStub<object>(); > > obj.Stub(x => x.ToString()).Return("my-tostring"); > > Assert.That(obj.ToString(), Is.SameAs("my-tostring")); > > } > > > [Test] > > public void StubToString_RecordReply() > > { > > var repository = new MockRepository(); > > var obj = repository.Stub<object>(); > > obj.Expect(x => x.ToString()).Return("my-tostring"); > > repository.ReplayAll(); > > > Assert.That(obj.ToString(), Is.SameAs("my-tostring")); > > repository.VerifyAll(); > > } > > } > > > In both tests, I get the following error on the obj.Stub() and the > > obj.Expect(): > > > System.InvalidOperationException: Invalid call, the last call has been > > used or no call has been made (make sure that you are calling a > > virtual (C#) / Overridable (VB) method). > > > Should this work? > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
