Please, tell my why it no work.

6 views
Skip to first unread message

Time

unread,
May 20, 2008, 10:46:21 AM5/20/08
to Rhino.Mocks
hi all!
I'm beginner in Rhino and mocking.
I have try mock simple property behavior, but it no work with error:
Test method TestProject1.Class2Test.FillHelloStringTest threw
exception: 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)..

Test method:
[TestMethod()]
public void FillHelloStringTest()
{
Class2 target = new Class2();
MockRepository mocks = new MockRepository();
MyDoc doc = mocks.CreateMock<MyDoc>(new object[] { "", null });//
as well how i can point that arguments for constructor does not
imposible for me
Expect.Call<String>(doc.HelloString).Return("Mike");
mocks.ReplayAll();
target.FillHelloString(doc);
Assert.AreEqual("Hello: Mike", target.Class2HelloString);
mocks.VerifyAll();
}

public class MyDoc
{
public String HelloString { get; set; }
public MyDoc(String string1, object object2)
{
}
}

class Class2
{
public String Class2HelloString { get; set; }

public void FillHelloString(MyDoc doc)
{
Class2HelloString = "Hello: " + doc.HelloString;
}
}

thanking you in anticipation

Maccari Claudio

unread,
May 20, 2008, 11:03:03 AM5/20/08
to Rhino...@googlegroups.com
You neeed to make HelloString virtual in order to mock it

public class MyDoc
{
public virtual String HelloString { get; set; }


public MyDoc(String string1, object object2)
{
}
}


HTH
m.

Richard...@quixotecorp.com

unread,
May 20, 2008, 11:10:11 AM5/20/08
to Rhino...@googlegroups.com
Hello there,

Erm... I suggest you start by reading the documentation. It really is
very helpful.

You must either make HelloString virtual, (or have it as part of an
interface) before you can use it in a mock call... just as the exception
is telling you.

In a "real world" application, it is likely that you would want an
IDocument (or similar) interface which MyDoc implements and Class2
consumes. That way you can easily verify both the implementation of
MyDoc, and the operation of Class2 in your unit testing. (Note: In that
scenario, you would only benefit from using RhinoMocks, or any mock
object framework, for testing Class2.)

Regards,
Richard

-----Original Message-----
From: Rhino...@googlegroups.com [mailto:Rhino...@googlegroups.com]
On Behalf Of Time

thanking you in anticipation

* C O N F I D E N T I A L I T Y N O T I C E *
-----------------------------------------------------------
The content of this e-mail is intended solely for the use of the individual or entity to whom it is addressed. If you have received this communication in error, be aware that forwarding it, copying it, or in any way disclosing its content to any other person, is strictly prohibited. Quixote Traffic Corporation is neither liable for the contents, nor for the proper, complete and timely transmission of (the information contained in) this communication. If you have received this communication in error, please notify the author by replying to this e-mail immediately and delete the material from any computer.

Time

unread,
May 20, 2008, 12:48:03 PM5/20/08
to Rhino.Mocks
Thank you
> thanking you in anticipation- Hide quoted text -
>
> - Show quoted text -

Time

unread,
May 20, 2008, 12:48:15 PM5/20/08
to Rhino.Mocks
Thank you
> The content of this e-mail is intended solely for the use of the individual or entity to whom it is addressed. If you have received this communication in error, be aware that forwarding it, copying it, or in any way disclosing its content to any other person, is strictly prohibited. Quixote Traffic Corporation is neither liable for the contents, nor for the proper, complete and timely transmission of (the information contained in) this communication. If you have received this communication in error, please notify the author by replying to this e-mail immediately and delete the material from any computer.- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages