Moq4: Setters on deep mocks no longer work after updating to 4.14.6 from old version

Created on 13 Oct 2020  路  8Comments  路  Source: moq/moq4

I've noticed after upgrade from an older version of Moq to the latest that setters on deep mocks no longer work. It's a bit of an annoyance to fix 100s of test cases with this issue.

Interfaces

```C#
public interface IFoo
{
int Property { get; set; }
}

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


#### Dosen't work
```C#
var bar = Mock.Of<IBar>(x => x.Foo.Property == 123);
Assert.AreEqual(123, bar.Foo.Property);

bar.Foo.Property = 321;
Assert.AreEqual(321, bar.Foo.Property); // Expected:<321>. Actual:<123>.

Works

```C#
var bar = Mock.Of(x => x.Foo == Mock.Of(y => y.Property == 123));
Assert.AreEqual(123, bar.Foo.Property);

bar.Foo.Property = 321;
Assert.AreEqual(321, bar.Foo.Property);
```

bug

All 8 comments

Is this related to #1039?

Issue still present in 4.14.6

Is this related to #1039?

I don't think so. #1039 targeted non-overridable / non-interceptable properties. In your case, we are looking at overridable properties. I'll look into it.

This stopped working with version 4.14.0; more precisely, with cb6b71a60df08a9c62b44ad6a33b608e4c0e11a1. Thanks for reporting, this should be fixed. For the time being, I'd suggest you stay with version 4.13.1.

Thank you for fixing it so quickly!
@stakx any chance of this fix being included in an earlier 4.14.7 release?

any chance of this fix being included in an earlier 4.14.7 release

I suppose I could do that, yes.

I suppose I could do that, yes.

That would be so great!

@vruss, I've pushed a hotfix release version 4.14.7 to NuGet. It should become available shortly.

Was this page helpful?
0 / 5 - 0 ratings