Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue on Dispose when using a Mock and Strict behavior (After 4.2.1402.2112) #143

Closed
DevShiny opened this issue Nov 19, 2014 · 2 comments
Closed

Comments

@DevShiny
Copy link

Copied open new report from here -- http://code.google.com/p/moq/issues/detail?id=379&start=100

What steps will reproduce the problem?

  1. Initialize a new Mock(MockBehavior.Strict):
    Mock mockWebClient = new Mock(MockBehavior.Strict);
  2. Setup the protected virtual Dispose method :
    mockWebClient.Protected().Setup("Dispose", ItExpr.IsAny());
  3. Call the Dispose method:
    using (WebClient client = mockWebClient.Object))
    {
    }

What is the expected output? What do you see instead?
It should work without error. But starting with the version 4.2.1408.619, I have an exception:
Test method XXX threw exception:
Moq.MockException: IDisposable.Dispose() invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.
Result StackTrace:
at Moq.ExtractProxyCall.HandleIntercept(ICallContext invocation, InterceptorContext ctx, CurrentInterceptContext localctx)
at Moq.Interceptor.Intercept(ICallContext invocation)
at Moq.Proxy.CastleProxyFactory.Interceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.WebClientProxy.Dispose()
at ...

The problem being that I can't mock the Dispose() method, it's not virtual. The Dispose method calls the protected virtual Dispose(bool) method, so my way should be the correct one.

Previously, I was using the version 4.2.1312.1622 and it was working correctly.
I tested all versions available on Nuget from 4.2.1312.1622 to 4.2.1408.717 (latest at the moment), and it stopped working at the version 4.2.1408.619.

What version of the product are you using? On what operating system?
Works correctly with nuget versions: 4.2.1312.1622, 4.2.1402.2112
Doesn't work with nuget versions: 4.2.1408.619, 4.2.1408.717 (latest ATM)
My operating system is Windows 7, I tested with Frameworks 4, 4.5 and 4.5.1

Please provide any additional information below.
/

Thank you

@ermshiperete
Copy link

Duplicate of #129

@kzu
Copy link
Contributor

kzu commented Feb 6, 2015

CallBase may be missing, and as noted on #129, you should set up the main
Dispose being called by the using, not the protected method.

/kzu from mobile
On Nov 19, 2014 5:03 PM, "DevShiny" notifications@github.com wrote:

Copied open new report from here --
http://code.google.com/p/moq/issues/detail?id=379&start=100

What steps will reproduce the problem?

  1. Initialize a new Mock(MockBehavior.Strict):
    Mock mockWebClient = new Mock(MockBehavior.Strict);
  2. Setup the protected virtual Dispose method :
    mockWebClient.Protected().Setup("Dispose", ItExpr.IsAny());
  3. Call the Dispose method:
    using (WebClient client = mockWebClient.Object))
    {
    }

What is the expected output? What do you see instead?
It should work without error. But starting with the version 4.2.1408.619,
I have an exception:
Test method XXX threw exception:
Moq.MockException: IDisposable.Dispose() invocation failed with mock
behavior Strict.
All invocations on the mock must have a corresponding setup.
Result StackTrace:

at Moq.ExtractProxyCall.HandleIntercept(ICallContext invocation,
InterceptorContext ctx, CurrentInterceptContext localctx)
at Moq.Interceptor.Intercept(ICallContext invocation)
at Moq.Proxy.CastleProxyFactory.Interceptor.Intercept(IInvocation
invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.WebClientProxy.Dispose()
at ...

The problem being that I can't mock the Dispose() method, it's not
virtual. The Dispose method calls the protected virtual Dispose(bool)
method, so my way should be the correct one.

Previously, I was using the version 4.2.1312.1622 and it was working
correctly.
I tested all versions available on Nuget from 4.2.1312.1622 to
4.2.1408.717 (latest at the moment), and it stopped working at the version
4.2.1408.619.

What version of the product are you using? On what operating system?
Works correctly with nuget versions: 4.2.1312.1622, 4.2.1402.2112
Doesn't work with nuget versions: 4.2.1408.619, 4.2.1408.717 (latest ATM)
My operating system is Windows 7, I tested with Frameworks 4, 4.5 and 4.5.1

Please provide any additional information below.
/

Thank you

Reply to this email directly or view it on GitHub
#143.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants