Skip to content

Commit

Permalink
More comments
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-xu committed Aug 6, 2014
1 parent 5804548 commit ceca9b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Source/InterceptorStrategies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ internal class InvokeBase : IInterceptStrategy
{
public InterceptionAction HandleIntercept(ICallContext invocation, InterceptorContext ctx, CurrentInterceptContext localctx)
{
if (invocation.Method.DeclaringType == typeof(object) ||
ctx.Mock.ImplementedInterfaces.Contains(invocation.Method.DeclaringType) && !invocation.Method.IsEventAttach() && !invocation.Method.IsEventDetach() && ctx.Mock.CallBase ||
invocation.Method.DeclaringType.IsClass && !invocation.Method.IsAbstract && ctx.Mock.CallBase
if (invocation.Method.DeclaringType == typeof(object) || // interface proxy
ctx.Mock.ImplementedInterfaces.Contains(invocation.Method.DeclaringType) && !invocation.Method.IsEventAttach() && !invocation.Method.IsEventDetach() && ctx.Mock.CallBase || // class proxy with explicitly implemented interfaces. The method's declaring type is the interface and the method couldn't be abstract
invocation.Method.DeclaringType.IsClass && !invocation.Method.IsAbstract && ctx.Mock.CallBase // class proxy
)
{
// Invoke underlying implementation.
Expand Down
18 changes: 16 additions & 2 deletions UnitTests/AsInterfaceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ public void ShouldBeAbleToCastToImplementedInterface()
Assert.DoesNotThrow(() => fooBar.As<IFoo>());
}

[Fact]
public void ShouldNotThrowIfCallExplicitlyImplementedInterfacesMethodWhenCallBaseIsTrue()
{
var fooBar = new Mock<FooBar>();
fooBar.CallBase = true;
var bag = (IBag)fooBar.Object;
Assert.DoesNotThrow(() => bag.Get("test"));
}

public interface IFoo
{
void Execute();
Expand Down Expand Up @@ -196,9 +205,14 @@ public abstract class FooBar : IFoo, IBag, IBar

public abstract int Value { get; set; }

public abstract void Add(string key, object o);
void IBag.Add(string key, object o)
{
}

public abstract object Get(string key);
object IBag.Get(string key)
{
return null;
}

public abstract void Test();
}
Expand Down

0 comments on commit ceca9b6

Please sign in to comment.