"Invalid when the mock object is in verified state"

938 views
Skip to first unread message

zkbi...@gmail.com

unread,
Dec 21, 2009, 3:20:34 PM12/21/09
to Rhino.Mocks
In our project we currently have ~330 tests (50% integration tests,
50% isolated unit tests). One test in particular passes locally, but
fails during our continuous integration build.

Here's the error message that we are getting:

"Test method [method name here] threw exception:
System.InvalidOperationException: This action is invalid when the mock
object is in verified state.."

What does this exception mean? I am seeing this error on 2 other
tests... so only 3 tests out of our 330 tests are getting this
exception when executed from the build server.

Any guidance would be greatly appreciated.

Tim Barcz

unread,
Dec 21, 2009, 3:41:32 PM12/21/09
to rhino...@googlegroups.com
Can you please post the test here? I suspect you're using Record/Replay semantics?

Tim


--

You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.





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

zkbi...@gmail.com

unread,
Dec 21, 2009, 4:01:48 PM12/21/09
to Rhino.Mocks
[TestMethod]
public void DeleteSchedOnDependencySpecification()
{
MockRepository repository = new MockRepository();
IDataAccess dal = repository.DynamicMock<IDataAccess>();
IServiceAgent agent = repository.DynamicMock<IServiceAgent>
();

int gateId = 1;
Yard yard = new Yard { YardId = 1, IpAddress =
"localhost" };

using (repository.Record())
{
dal.GetYardByGateId(gateId);
LastCall.Return(yard);

agent.DeleteSched(default(Guid), yard.IpAddress);
LastCall.IgnoreArguments().Return(true);
}

ManagerRegistry.GateEventManager.YardServiceAgent = agent;
ManagerRegistry.SetYardManager(dal);
ManagerRegistry.GateEventManager.DeleteSched(default
(Guid), gateId);

repository.VerifyAll();
}

The ManagerRegistry.GateEventManager component exposes a "DeleteSched"
method that internally uses the second paramater to look up
encapsulated knowledge (i.e. Yard.IpAddress). The
ManagerRegistry component manages the singleton nature of the
GateEventManager component.

When I run just this test locally it passes with no exceptions. When I
run this in conjunction with other tests it fails.

The test always fails on the following line:

"ManagerRegistry.GateEventManager.YardServiceAgent = agent;"


On Dec 21, 1:41 pm, Tim Barcz <timba...@gmail.com> wrote:
> Can you please post the test here? I suspect you're using Record/Replay
> semantics?
>
> Tim
>

> On Mon, Dec 21, 2009 at 2:20 PM, zkBier...@gmail.com <zkbier...@gmail.com>wrote:
>
>
>
>
>
> > In our project we currently have ~330 tests (50% integration tests,
> > 50% isolated unit tests). One test in particular passes locally, but
> > fails during our continuous integration build.
>
> > Here's the error message that we are getting:
>
> > "Test method [method name here] threw exception:
> > System.InvalidOperationException: This action is invalid when the mock
> > object is in verified state.."
>
> > What does this exception mean? I am seeing this error on 2 other
> > tests... so only 3 tests out of our 330 tests are getting this
> > exception when executed from the build server.
>
> > Any guidance would be greatly appreciated.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Rhino.Mocks" group.
> > To post to this group, send email to rhino...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > rhinomocks+...@googlegroups.com<rhinomocks%2Bunsubscribe@googlegrou­ps.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rhinomocks?hl=en.
>
> --
> Tim Barcz
> Microsoft C# MVP

> Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz- Hide quoted text -
>
> - Show quoted text -

Tim Barcz

unread,
Dec 21, 2009, 5:39:31 PM12/21/09
to rhino...@googlegroups.com
Are you missing

using (repository.Playback())
{

}

around the ManagerRegistry calls? It seems as though you're mixing the classic and "using" syntaxes for Record/Replay.

Tim

To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.





--
Tim Barcz
Microsoft C# MVP

zkbi...@gmail.com

unread,
Dec 21, 2009, 6:51:42 PM12/21/09
to Rhino.Mocks
Could you provide me with an example of how you would re-write this
particular test using the syntax you suggest? Thanks!

On Dec 21, 3:39 pm, Tim Barcz <timba...@gmail.com> wrote:
> Are you missing
>
> using (repository.Playback())
> {
>
> }
>
> around the ManagerRegistry calls? It seems as though you're mixing the
> classic and "using" syntaxes for Record/Replay.
>
> Tim
>

Reply all
Reply to author
Forward
0 new messages