Hi,
I'm receiving InvalidOperationException in the attached code example, using
last rhino mocks.
Here is the stacktrace:
at System.Reflection.RuntimeMethodInfo.GetGenericMethodDefinition()
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.MethodsEquals(
MethodInfo method, ProxyMethodExpectationTriplet triplet)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.
GetAllExpectationsForProxyAndMethod(Object proxy, MethodInfo method)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.CalcExpectedAndActual
.Calculate(Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.UnexpectedMethodCall(
IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.
DoGetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo
method, Object[] args)
at Rhino.Mocks.MethodRecorders.MethodRecorderBase.GetRecordedExpectation(
IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation invocation,
MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation,
MethodInfo method, Object[] args)
at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object
proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.Invocation.Actions.RegularInvocation.PerformAgainst(
IInvocation invocation)
at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IDbHandlerProxy6d12ffc56cb147579f1dff408afd8d46.IDbHandler
.OpenUoW<T>()
at ConsoleApplication1.UnitTest.MethodName() in UnitTest.cs: line
28<projectfile:D0A5D1D0-21A3-40B9-91D6-5BAF7FB6C545%2Ff%3AUnitTest.cs%3F28%3F1>
I know that my expectations are not actually right - I set an expectation
onto non-generic method, but call generic method. Though I would expect to
receive more meaningful exception from Rhino.Mock
I've caught this while debugging my test for the real application, and
spent a lot of time debugging Rhino.Mocks while I figured out the error.
It looks like the method in Rhino.Mocks: UnorderedMethodRecorder.
MethodsEquals(MethodInfo method, ProxyMethodExpectationTriplet triplet)
has this code:
if(method.IsGenericMethod==false)
return triplet.Method == method;
return triplet.Method.GetGenericMethodDefinition()
== method.GetGenericMethodDefinition();
which actually does not count a situation when *method* is generic, but
*triplet.Method
*is not - this is exactly my situation. Call to
*triplet.Method.GetGenericMethodDefinition()
*fails because of that.
There should be one additional check, like this:
if (method.IsGenericMethod != triplet.Method.IsGenericMethod)
return false;
If I am right, and there is no catch, where should I report this or make a
pull request? Looks like https://github.com/ayende/rhino-mocks is abandoned.
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/groups/opt_out.
?using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
namespace ConsoleApplication1
{
[TestFixture]
class UnitTest
{
[Test(Description = "Description")]
public void MethodName()
{
var mockRepostitory = new MockRepository();
IDbHandler dbHandler = mockRepostitory.StrictMock<IDbHandler>();
var dbStatefulUnitOfWork = mockRepostitory.StrictMock<DutIdUnitOfWork>(dbHandler);
using (mockRepostitory.Record())
{
dbHandler.Expect(x => x.OpenStatefulDutIdUoW()).Return(dbStatefulUnitOfWork);
}
using (mockRepostitory.Playback())
{
DutIdUnitOfWork a = dbHandler.OpenUoW<DutIdUnitOfWork>();
}
}
}
public interface IDbHandler
{
DutIdUnitOfWork OpenStatefulDutIdUoW();
T OpenUoW<T>();
}
public class DutIdUnitOfWork
{
public DutIdUnitOfWork(IDbHandler dbHandler)
{
}
}
}