TestControllerBuilder.ctor() throws Use Arg<T> ONLY within a mock method call while recording. 0 arguments expected, 1 have been defined.

575 views
Skip to first unread message

Mihai Lazar

unread,
Jul 18, 2011, 10:08:53 AM7/18/11
to mvccontri...@googlegroups.com
Hi,

We have some 120+ test. They usually start with in the BeforeEach method, which is annotated with [SetUp]
  _controller = new WhateverController();
 
            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(_controller);
after test numer 112 it throws the following error on whichever method finds itself to be 113. We are using NUnit 2.5.3
Test 'Tests.Unit.Controllers.Areas.OnBoarding.CandidateController_Tests.GET_Create_Binds_SelectListItems' failed: System.InvalidOperationException : Use Arg<T> ONLY within a mock method call while recording. 0 arguments expected, 1 have been defined.
at Rhino.Mocks.ArgManager.CheckMethodSignature(MethodInfo method)
at Rhino.Mocks.Impl.RecordMockState.BuildParamExpectation(IInvocation invocation, MethodInfo method)
at Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args)
at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at HttpContextBaseProxyffe087d8ba564f10bc50e4070acb37f2.get_Session()
at lambda_method(Closure , HttpContextBase )
at MvcContrib.TestHelper.MockFactories.RhinoMocksProxy`1.SetupMockBehavior[TResult](Expression`1 expression, String behaviorName, Object[] behaviorArguments)
at MvcContrib.TestHelper.MockFactories.RhinoMocksProxy`1.ReturnFor[TResult](Expression`1 expression, TResult result)
at MvcContrib.TestHelper.TestControllerBuilder.Setup(IMockFactory factory)
at MvcContrib.TestHelper.TestControllerBuilder..ctor(IMockFactory mockFactory)
at MvcContrib.TestHelper.TestControllerBuilder..ctor()
Unit\Controllers\Areas\OnBoarding\CandidateController_Tests.cs(38,0): at Tests.Unit.Controllers.Areas.OnBoarding.CandidateController_Tests.BeforeEach()

Is there some sort of cleanup I should be doing ?

Jeremy Skinner

unread,
Jul 18, 2011, 10:13:57 AM7/18/11
to mvccontri...@googlegroups.com
So this is a Rhino Mocks error, not actually TestControllerBuilder. Is your test project using RhinoMocks? The TestControllerBuilder is using Rhino Mocks internally, and if your own tests using RM aren't properly being cleaned up then this could confuse the TestControllerBuilder. Make sure that if you're using Rhino Mocks' Record/Replay syntax that you have your Playback/ReplayAll method calls in the right place. I can't really provide any more help without actually seeing the tests.

Jeremy

--
Contact Jeffrey Palermo or Eric Hexter with specific questions about the MvcContrib project. Or go to http://mvccontrib.org
 
To unsubscribe from this group, send email to mvccontrib-disc...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mvccontrib-discuss?hl=en

Mihai Lazar

unread,
Jul 18, 2011, 10:51:22 AM7/18/11
to mvccontri...@googlegroups.com
General usage would be something like this
_queryService = MockRepository.GenerateMock<IQueryService<Candidate>>();

but I don't always set expections on the service.

You are saying I should use _queryService.VerifyAllExpectations() in order to clean up Rhino Mocks ?

Jeremy Skinner

unread,
Jul 18, 2011, 10:54:17 AM7/18/11
to mvccontri...@googlegroups.com
No - I meant only if you're using the Record/Replay syntax. Looks like you're using the AAA syntax. If you could provide a sample that reproduces the problem then I'll be able to help more.

--

Mihai Lazar

unread,
Jul 18, 2011, 11:16:13 AM7/18/11
to mvccontri...@googlegroups.com
It only reproduces after 100+ tests run with NUnit runner, so giving the source code for this is out of the question.

Would it be possible to initialize the TestControllerBuilder with a different MockFactory manually ? or by setting another instance than the one used by static class MockRepository ?

Jeremy Skinner

unread,
Jul 18, 2011, 11:22:26 AM7/18/11
to mvccontri...@googlegroups.com
The current implementation always uses a new MockRepository for each TestControllerBuilder instance.

Internally, the TestControllerBuilder uses a MockFactory abstraction (which allows it to be used with either Rhino Mocks or Moq - see http://mvccontrib.codeplex.com/SourceControl/changeset/view/fd203ec60f94#src%2fMvcContrib.TestHelper%2fMvcContrib.TestHelper%2fTestControllerBuilder.cs).

I believe that the Rhino Mocks implementation of IMockFactory always creates a new MockRepository (although this is not an area of the codebase with which I'm familiar).

You could customize the behaviour, but this would likely require implementing your own IMockFactory.

On 18 July 2011 16:16, Mihai Lazar <lazar.fl...@gmail.com> wrote:
It only reproduces after 100+ tests run with NUnit runner, so giving the source code for this is out of the question.

Would it be possible to initialize the TestControllerBuilder with a different MockFactory manually ? or by setting another instance than the one used by static class MockRepository ?

--

Mihai Lazar

unread,
Jul 19, 2011, 3:57:03 AM7/19/11
to mvccontri...@googlegroups.com
I copy pasted the internal MoqFactory into my test project and constructed TestControllerBuilder with it. It works fine now.
Reply all
Reply to author
Forward
0 new messages