First I'd suggest using interfaces... secondly if you are mocking a class
the mocked methods/properties must be marked as virtual, which is pretty
much what the error message has said.

On 4 February 2010 07:02, TheMightyKumquat <[email protected]> wrote:

> This shouldn't be causing problems, but somehow it is. Possibly it's
> related to my inexperience using stubs, or possibly it's that I'm
> trying to stub a class.
>
> class MyDocument{
>
>   public DocumentHeader Header { get; set; }
>
> //...
> }
>
> class DocumentHeader{
>
> public bool AuditingRequired { get; set; }
> //...
> }
>
> class ClassBeingTested {
>   public void HandleAudit(MyDocument doc)
>   {
>      if (doc.Header.AuditingRequired)
>      {
>        // do things
>      }
>   }
> }
>
> I'm testing the HandleAudit method, and the scenario tested is that
> AuditingRequired is false.
> I:
> - set up a MyDocument object with a DocumentHeader property,
> - set up the value false for its AuditingRequired property to return
> and
> - feed those stubbed values into the method.
>
> But I'm trying to stub the MyDocument and the DocumentHeader classes,
> and I can't seem to set them up properly.
>
> [TestMethod]
> public void MyTest()
> {
>            //ARRANGE
>            ClassBeingTested target = new ClassBeingTested();
>
>            // This works
>            MyDocument fakeMyDoc=
> MockRepository.GenerateStub<MyDocument>();
>            HeaderDocument fakeHeader =
> MockRepository.GenerateStub<DocumentHeader>();
>
>            // This throws an exception
>
> SetupResult.For(fakeHeader.AuditingRequired).Return(false);
>
> SetupResult.For(fakeResponse.HeaderDocument).Return(fakeHeader);
>
>            //ACT
>            target.HendleAudit()
>
>           // ASSERT
>          ....
> }
>
> My test throws an exception at the SetupResult lines -
> 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)..
>
> I can't see what I'm doing wrong - any ideas, please?
>
> --
> 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]<rhinomocks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rhinomocks?hl=en.
>
>

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