Skip to content

Commit

Permalink
Must mark setups resulting from DefaultValue.Mock as matched
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Jun 18, 2020
1 parent 8eb2999 commit 4d6c7bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Moq/Interception/InterceptionAspects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,13 @@ public static void Handle(Invocation invocation, Mock mock)
var returnValue = mock.GetDefaultValue(method, out var innerMock);
if (innerMock != null && invocation.MatchingSetup == null)
{
mock.AddInnerMockSetup(invocation, returnValue);
var setup = mock.AddInnerMockSetup(invocation, returnValue);
setup.Execute(invocation);
}
else
{
invocation.Return(returnValue);
}
invocation.Return(returnValue);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Moq/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ internal object GetDefaultValue(MethodInfo method, out Mock candidateInnerMock,

#region Inner mocks

internal void AddInnerMockSetup(Invocation invocation, object returnValue)
internal InnerMockSetup AddInnerMockSetup(Invocation invocation, object returnValue)
{
var method = invocation.Method;

Expand Down Expand Up @@ -819,7 +819,9 @@ internal void AddInnerMockSetup(Invocation invocation, object returnValue)
Debug.Assert(property.CanRead(out var getter) && invocation.Method == getter);
}

this.MutableSetups.Add(new InnerMockSetup(originalExpression: null, this, new InvocationShape(expression, invocation.Method, arguments, exactGenericTypeArguments: true), returnValue));
var setup = new InnerMockSetup(originalExpression: null, this, new InvocationShape(expression, invocation.Method, arguments, exactGenericTypeArguments: true), returnValue);
this.MutableSetups.Add(setup);
return setup;
}

#endregion
Expand Down

0 comments on commit 4d6c7bd

Please sign in to comment.