Permalink
Browse files

Fix issue with stubbing a method returning a delegate

  • Loading branch information...
dahlbyk committed Sep 19, 2010
2 parents d458e60 + 5b337e8 commit 9a2f5e1620b4bf9676653a183c824480d4394115
@@ -0,0 +1,53 @@
+namespace Rhino.Mocks.Tests.FieldsProblem
+{
+ using System;
+ using Rhino.Mocks.Interfaces;
+ using Xunit;
+
+ public class FieldProblem_KeithD
+ {
+ [Fact]
+ public void ImplementedTypesOfTargetOfMockedDelegateDoesNotContainDelegateType()
+ {
+ var mockDelegate = MockRepository.GenerateMock<EventHandler>();
+
+ var mockTarget = mockDelegate.Target as IMockedObject;
+
+ Assert.NotNull(mockTarget);
+ Assert.DoesNotContain(typeof(EventHandler), mockTarget.ImplementedTypes);
+ }
+
+ [Fact]
+ public void CanStubReturningAnonymousDelegateTwice()
+ {
+ var foo = MockRepository.GenerateMock<IFoo>();
+
+ foo.Stub(x => x.Bar(0)).Return(() => 2);
+ foo.Stub(x => x.Bar(1)).Return(() => 4);
+
+ Assert.Equal(2, foo.Bar(0)());
+ Assert.Equal(4, foo.Bar(1)());
+ }
+
+ [Fact]
+ public void CanStubReturningNonAnonymousDelegateTwice()
+ {
+ var foo = MockRepository.GenerateMock<IFoo>();
+
+ foo.Stub(x => x.Bar(0)).Return(Return2);
+ foo.Stub(x => x.Bar(1)).Return(Return4);
+
+ Assert.Equal(2, foo.Bar(0)());
+ Assert.Equal(4, foo.Bar(1)());
+ }
+
+ public interface IFoo
+ {
+ Func<int> Bar(int baz);
+ }
+
+ private static int Return2() { return 2; }
+
+ private static int Return4() { return 4; }
+ }
+}
@@ -175,6 +175,7 @@
<Compile Include="FieldsProblem\FieldProblem_Alex.cs" />
<Compile Include="FieldsProblem\FieldProblem_Bill.cs" />
<Compile Include="FieldsProblem\FieldProblem_JPBoodhoo.cs" />
+ <Compile Include="FieldsProblem\FieldProblem_KeithD.cs" />
<Compile Include="MethodProblems\MethodProblem_JPBoodhoo.cs" />
<Compile Include="PartialMockTestsAAA.cs" />
<Compile Include="MultiMocksWithAAA.cs" />
@@ -785,7 +785,7 @@ private object MockDelegate(CreateMockState mockStateFactory, Type type)
object proxy;
- ProxyInstance proxyInstance = new ProxyInstance(this, type);
+ ProxyInstance proxyInstance = new ProxyInstance(this);
RhinoInterceptor interceptor = new RhinoInterceptor(this, proxyInstance,invocationVisitorsFactory.CreateStandardInvocationVisitors(proxyInstance, this));
Type[] types = new Type[] { typeof(IMockedObject) };

0 comments on commit 9a2f5e1

Please sign in to comment.