Skip to content

Commit ab83afc

Browse files
committed
Merge branch 'inner-mocks-inherit-setupallproperties' into hotfix-release
2 parents d3128ef + 2363e09 commit ab83afc

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
66

77
## Unreleased
88

9+
#### Changed
10+
11+
* Mocks created by `DefaultValue.Mock` now inherit `SetupAllProperties` from their "parent" mock (like it says in the XML documentation) (@stakx, #1074)
12+
913
#### Fixed
1014

1115
* Setup not triggered due to VB.NET transparently inserting superfluous type conversions into a setup expression (@InteXX, #1067)
16+
* Nested mocks created by `Mock.Of<T>()` no longer have their properties stubbed since version 4.14.0 (@vruss, @1071)
1217

1318

1419
## 4.14.6 (2020-09-30)

src/Moq/MockDefaultValueProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected override object GetFallbackDefaultValue(Type type, Mock mock)
3636
var mockType = typeof(Mock<>).MakeGenericType(type);
3737
Mock newMock = (Mock)Activator.CreateInstance(mockType, mock.Behavior);
3838
newMock.DefaultValueProvider = mock.DefaultValueProvider;
39+
newMock.AutoSetupPropertiesDefaultValueProvider = mock.AutoSetupPropertiesDefaultValueProvider;
3940
if(!type.IsDelegateType())
4041
{
4142
newMock.CallBase = mock.CallBase;

tests/Moq.Tests/Regressions/IssueReportsFixture.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,43 @@ public class DatabaseOptions
34513451

34523452
#endregion
34533453

3454+
#region 1071
3455+
3456+
public class Issue1071
3457+
{
3458+
public interface IFoo
3459+
{
3460+
int Property { get; set; }
3461+
}
3462+
3463+
public interface IBar
3464+
{
3465+
IFoo Foo { get; set; }
3466+
}
3467+
3468+
[Fact]
3469+
public void Property_set_up_with_Mock_Of__is_automatically_stubbed__automatic_inner_mock()
3470+
{
3471+
var bar = Mock.Of<IBar>(x => x.Foo.Property == 123);
3472+
Assert.Equal(123, bar.Foo.Property);
3473+
3474+
bar.Foo.Property = 321;
3475+
Assert.Equal(321, bar.Foo.Property);
3476+
}
3477+
3478+
[Fact]
3479+
public void Property_set_up_with_Mock_Of_is_automatically_stubbed__manual_inner_mock()
3480+
{
3481+
var bar = Mock.Of<IBar>(x => x.Foo == Mock.Of<IFoo>(y => y.Property == 123));
3482+
Assert.Equal(123, bar.Foo.Property);
3483+
3484+
bar.Foo.Property = 321;
3485+
Assert.Equal(321, bar.Foo.Property);
3486+
}
3487+
}
3488+
3489+
#endregion
3490+
34543491
// Old @ Google Code
34553492

34563493
#region #47

0 commit comments

Comments
 (0)