Skip to content

Commit

Permalink
Make DefaultValue.Mock inherit property stubbing
Browse files Browse the repository at this point in the history
The XML doc comment for `Mock<T>.SetupAllProperties()` states that:

> If the mock's `DefaultValue` is set to `DefaultValue.Mock`, the
> mocked default values will also get all properties setup recursively.

But this does not actually happen! This commit changes the behavior of
`DefaultValue.Mock` such that it does what it says on the tin.

In theory, this could be a breaking change; let's see how many users
have relied on behavior that contradicts the documentation.

References:
https://github.com/moq/moq4/blob/947c6a0aa1bbf265b5555ad0a84beb5bfc53b4e2/src/Moq/Mock.Generic.cs#L671-L674
  • Loading branch information
stakx committed Oct 13, 2020
1 parent 15dd8e9 commit aea3f71
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/Moq/MockDefaultValueProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override object GetFallbackDefaultValue(Type type, Mock mock)
var mockType = typeof(Mock<>).MakeGenericType(type);
Mock newMock = (Mock)Activator.CreateInstance(mockType, mock.Behavior);
newMock.DefaultValueProvider = mock.DefaultValueProvider;
newMock.AutoSetupPropertiesDefaultValueProvider = mock.AutoSetupPropertiesDefaultValueProvider;
if(!type.IsDelegateType())
{
newMock.CallBase = mock.CallBase;
Expand Down

0 comments on commit aea3f71

Please sign in to comment.