-
-
Notifications
You must be signed in to change notification settings - Fork 813
Somethings up with strict mock with recent changes #273
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
Comments
I observe the same issue after upgrade from version 4.5.13 to 4.5.16. I get following exception: Moq.MockException: Object.ToString() invocation failed with mock behavior Strict. Result stack trace is: |
I just linked at the feature that caused this breakage. The ability to mock System.Object members was done like all other method setups, and it should be done always with a "loose mock" behavior instead, to avoid this very issue. |
…ne of them were set up. Fixes devlooped#273.
I still feel there is a potential regression (unless this functionality is by design). The following code will execute without an exception on 4.5.13, but will throw on 4.5.19 ("Object.GetHashCode() invocation failed with mock behavior Strict"):
Is that desired? |
Really? @kolomanschaft? |
Yeah @kzu, it appears that the same issue would occur with |
Interesting @BrianLunardini. The test I wrote for those methods passed. It is past 8pm over here. I'll have a look first thing tomorrow morning. |
Thanks @kolomanschaft ! |
…ct methods in the interceptor context. Fixes devlooped#273 (again :-))
Accidentally used |
What nuget package will this be available in? |
Thanks @kolomanschaft! @wyattwebb I just grabbed 4.5.21 from NuGet and verified it had the fix. |
When using strict moq I am getting inconsistent errors. I'm using MOQ and Autofixture in my main project where I am getting failed tests for Object.ToString() not being set up for a strict Mock. Using this in a vanilla project I get Object.GetHashCode not set up on a strict mock. I may be missing something easy but attached is a sample test project
Moq4516Tests.zip
Test Name: GetHashCodeTestFailure
Test FullName: Moq4516Tests.UnitTests.GetHashCodeTestFailure
Test Source: C:\Users\wwebb\Documents\Visual Studio 2015\Projects\Moq4516Tests\Moq4516Tests\UnitTest1.cs : line 54
Test Outcome: Failed
Test Duration: 0:00:00.3059009
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.ObjectProxy.GetHashCode()
at Moq.Interceptor.ExpressionKey.GetHashCode()
at System.Collections.Generic.ObjectEqualityComparer
1.GetHashCode(T obj) at System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add)at System.Collections.Generic.Dictionary
2.set_Item(TKey key, TValue value) at Moq.Interceptor.AddCall(IProxyCall call, SetupKind kind) at Moq.Mock.<>c__DisplayClass61_0
2.b__0()at Moq.PexProtector.Invoke[T](Func
1 function) at Moq.Mock.Setup[T,TResult](Mock
1 mock, Expression1 expression, Condition condition) at Moq.Mock
1.Setup[TResult](Expression`1 expression)at Moq4516Tests.UnitTests.GetHashCodeTestFailure() in C:\Users\wwebb\Documents\Visual Studio 2015\Projects\Moq4516Tests\Moq4516Tests\UnitTest1.cs:line 60
Result Message:
Test method Moq4516Tests.UnitTests.GetHashCodeTestFailure threw exception:
Moq.MockException: Object.GetHashCode() invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.
The text was updated successfully, but these errors were encountered: