Skip to content

Commit

Permalink
Don't attempt to set CallBase on auto-generated mocks for delegates (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
dammejed authored and ishimko committed Sep 2, 2019
1 parent 9faaa67 commit 948d380
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
#### Fixed

* Regression: `SetupAllProperties` can no longer set up properties whose names start with `Item`. (@mattzink, #870; @kaan-kaya, #869)
* Regression: `MockDefaultValueProvider` will no longer attempt to set `CallBase` to true for mocks generated for delegates. (@dammejed, #874)


## 4.12.0 (2019-06-20)
Expand Down
5 changes: 4 additions & 1 deletion src/Moq/MockDefaultValueProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ 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.CallBase = mock.CallBase;
if(!type.IsDelegate())
{
newMock.CallBase = mock.CallBase;
}
newMock.Switches = mock.Switches;
return newMock.Object;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,35 @@ public abstract partial class HttpContext

#endregion

#region 874
public class Issue874
{
[Fact]
public void MockDefaultValueProvider_will_Propagate_Callbase_to_nondelegates()
{
var mock = new Mock<IDictionary<string, IDictionary<string, string>>>()
{
CallBase = true,
DefaultValue = DefaultValue.Mock
};
var mockedIndexResult = mock.Object["foo"];
Assert.Null(mockedIndexResult["foo"]);
}

[Fact]
public void MockDefaultValueProvide_will_not_propagate_Callback_to_delegates()
{
var mock = new Mock<IDictionary<string, Func<string>>>()
{
CallBase = true,
DefaultValue = DefaultValue.Mock
};
var mockedIndexResult = mock.Object["foo"];
Assert.Null(mockedIndexResult());
}
}
#endregion

// Old @ Google Code

#region #47
Expand Down

0 comments on commit 948d380

Please sign in to comment.