Skip to content

Commit

Permalink
Merge branch 'inner-mocks-inherit-setupallproperties' into hotfix-rel…
Browse files Browse the repository at this point in the history
…ease
stakx committed Oct 14, 2020
2 parents d3128ef + 2363e09 commit ab83afc
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,9 +6,14 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1

## Unreleased

#### Changed

* Mocks created by `DefaultValue.Mock` now inherit `SetupAllProperties` from their "parent" mock (like it says in the XML documentation) (@stakx, #1074)

#### Fixed

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


## 4.14.6 (2020-09-30)
1 change: 1 addition & 0 deletions src/Moq/MockDefaultValueProvider.cs
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 37 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
@@ -3451,6 +3451,43 @@ public class DatabaseOptions

#endregion

#region 1071

public class Issue1071
{
public interface IFoo
{
int Property { get; set; }
}

public interface IBar
{
IFoo Foo { get; set; }
}

[Fact]
public void Property_set_up_with_Mock_Of__is_automatically_stubbed__automatic_inner_mock()
{
var bar = Mock.Of<IBar>(x => x.Foo.Property == 123);
Assert.Equal(123, bar.Foo.Property);

bar.Foo.Property = 321;
Assert.Equal(321, bar.Foo.Property);
}

[Fact]
public void Property_set_up_with_Mock_Of_is_automatically_stubbed__manual_inner_mock()
{
var bar = Mock.Of<IBar>(x => x.Foo == Mock.Of<IFoo>(y => y.Property == 123));
Assert.Equal(123, bar.Foo.Property);

bar.Foo.Property = 321;
Assert.Equal(321, bar.Foo.Property);
}
}

#endregion

// Old @ Google Code

#region #47

0 comments on commit ab83afc

Please sign in to comment.