Regression in v3 with Expect.Call being invoked with method having a generic return type

90 views
Skip to first unread message

michael.r

unread,
Mar 6, 2007, 5:10:58 AM3/6/07
to Rhino.Mocks
Hello Ayende
I found another regression bug form version 2.9.6. I have the
interface IGenericType with the type parameter T. MyMethod is part of
this interface and uses T as its return type. When create a mock for
IGenericType and then set up an expection for MyMethod, the ReturnType
is a null reference 1).

[TestFixture]
public class TestWithMethodHavingAGenericReturnType
{
[Test]
public void Execute ()
{
MockRepository mocks = new MockRepository ();
IGenericType<object> mock =
mocks.CreateMock<IGenericType<object>> ();
IMethodOptions methodOptions = Expect.Call (mock.MyMethod ());
//Assert.IsNotNull (methodOption.expectation.Method.ReturnType,
"True in 2.9.6");
methodOptions.Do ((MyDelegate) delegate { return new object
(); });
}
}

public interface IGenericType<T>
{
T MyMethod ();
}

public delegate object MyDelegate ();

(1) In the Orcas CTP the mscorlib gets updated to 2.0.50727.1302. The
behavior is different then with the ReturnType actually having a
value.

Regards, Michael

Fabian Schmied

unread,
Mar 6, 2007, 7:51:32 AM3/6/07
to Rhino.Mocks
> I found another regression bug form version 2.9.6. I have the
> interface IGenericType with the type parameter T. MyMethod is part of
> this interface and uses T as its return type. When create a mock for
> IGenericType and then set up an expection for MyMethod, the ReturnType
> is a null reference 1).

[...]

To add some more information to this issue - the line
"methodOptions.Do(...);" fails with the following exception:

System.InvalidOperationException: The delegate return value should be
assignable from
at
Rhino.Mocks.Expectations.AbstractExpectation.AssertReturnTypeMatch(Delegate
value) in C:\...\RhinoMocks\Sources\rhino-mocks\Rhino.Mocks
\Expectations\AbstractExpectation.cs:line 483
at
Rhino.Mocks.Expectations.AbstractExpectation.set_ActionToExecute(Delegate
value) in C:\...\RhinoMocks\Sources\rhino-mocks\Rhino.Mocks
\Expectations\AbstractExpectation.cs:line 202
at Rhino.Mocks.Impl.MethodOptions.Do(Delegate action) in C:\...
\RhinoMocks\Sources\rhino-mocks\Rhino.Mocks\Impl\MethodOptions.cs:line
87
at Tests.Test.Execute() in C:\...\GenericRhinoTests
\GenericRhinoTests\Test.cs:line 23

Even with mscorlib 2.0.50727.1302, this doesn't work.

The reason for this is that RhinoInvocation stores the method obtained
via DynamicProxy's IInvocation.Method property in its repository.
IInvocation.Method points to the original, uninstantiated
IGenericType<>.MyMethod, which has a generic return type (T). This
generic return type is not assignable from the return type of the
method passed to Do (object), leading to the exception.

To remedy this, RhinoInvocation should store the instantiated
IGenericType<object>.MyMethod (or its subclasses) in its repository.

I'm not sure whether the problem should be fixed in RhinoMocks or
DynamicProxy 2, though. I guess DP 2 shouldn't return
IGenericType<>.MyMethod in its IInvocation.Method property - it was
asked to proxy IGenericType<object> after all (unless I'm missing
something).

Regards,
Fabian

Ayende Rahien

unread,
Mar 9, 2007, 9:53:03 AM3/9/07
to Rhino...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages