Your mock repository is probably still in "Record" mode.  Before you
start using any of your mocks, put the repository into "Playback" mode
with (IIRC):

mocks.ReplayAll();

Or, the easier thing would be to switch to the new AAA
(Arrange/Act/Assert) syntax.  It's a little easier to set up (IMO) and
doesn't have some of the complexities of the Record/Replay semantics:

var mockState = MockRepository.GenerateMock<PageStateWrapper>();
mockState.Expect(s => s.PageState()).Return(0);

RecommendationState recState = new RecommendationState(mockState);

mockState.VerifyAll();

---
Patrick Steele
http://weblogs.asp.net/psteele



On Fri, Oct 21, 2011 at 10:45 AM, Steven Solomon
<[email protected]> wrote:
> Hi all,
>
> I have tried looking for a solution before posting so forgive me if
> this is duplicate.
>
> I am trying to mock a class and expect a method call on the
> constructor however I get ....
>
> "Test method
> BaynoteControlTests.RecommendationStateTests.StateConstructor 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)."
>
> Here is my test code ...
>
> [TestMethod]
>        public void StateConstructor()
>        {
>            MockRepository mocks = new MockRepository();
>            PageStateWrapper mockState =
> mocks.StrictMock<PageStateWrapper>();
>
>            Expect.Call(mockState.PageState()).Return(0);
>
>            RecommendationState recState = new
> RecommendationState(mockState);
>
>            mocks.VerifyAll();
>        }
>
> --
> 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.
>
>

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