Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setters on deep mocks no longer work after updating to 4.14.6 from old version #1071

Closed
vruss opened this issue Oct 13, 2020 · 8 comments · Fixed by #1074
Closed

Setters on deep mocks no longer work after updating to 4.14.6 from old version #1071

vruss opened this issue Oct 13, 2020 · 8 comments · Fixed by #1074
Assignees
Labels
Milestone

Comments

@vruss
Copy link

vruss commented Oct 13, 2020

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

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

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

Dosen't work

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

var bar = Mock.Of<IBar>(x => x.Foo == Mock.Of<IFoo>(y => y.Property == 123));
Assert.AreEqual(123, bar.Foo.Property);

bar.Foo.Property = 321;
Assert.AreEqual(321, bar.Foo.Property);
@vruss vruss changed the title Setters on deep mocks no longer work after updating from old version Setters on deep mocks no longer work after updating to 4.15.5 from old version Oct 13, 2020
@vruss
Copy link
Author

vruss commented Oct 13, 2020

Is this related to #1039?

@vruss vruss changed the title Setters on deep mocks no longer work after updating to 4.15.5 from old version Setters on deep mocks no longer work after updating to 4.15.6 from old version Oct 13, 2020
@vruss
Copy link
Author

vruss commented Oct 13, 2020

Issue still present in 4.14.6

@vruss vruss changed the title Setters on deep mocks no longer work after updating to 4.15.6 from old version Setters on deep mocks no longer work after updating to 4.14.6 from old version Oct 13, 2020
@stakx
Copy link
Contributor

stakx commented Oct 13, 2020

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.

@stakx
Copy link
Contributor

stakx commented Oct 13, 2020

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

@stakx stakx added the bug label Oct 13, 2020
@stakx stakx self-assigned this Oct 13, 2020
@stakx stakx added this to the 4.15.0 milestone Oct 13, 2020
@vruss
Copy link
Author

vruss commented Oct 14, 2020

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

@stakx
Copy link
Contributor

stakx commented Oct 14, 2020

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

I suppose I could do that, yes.

@vruss
Copy link
Author

vruss commented Oct 14, 2020

I suppose I could do that, yes.

That would be so great!

@stakx stakx modified the milestones: 4.15.0, 4.14.7 Oct 14, 2020
@stakx
Copy link
Contributor

stakx commented Oct 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants