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

Property stubs not working on sub mock

Closed
aaronburro opened this issue Mar 4, 2022 · 5 comments · Fixed by #1241
Closed

Property stubs not working on sub mock #1240

aaronburro opened this issue Mar 4, 2022 · 5 comments · Fixed by #1241
Assignees
Labels
Milestone

Comments

@aaronburro
Copy link

aaronburro commented Mar 4, 2022

IDE: Visual Studio 2019
.NET: Framework 4.5.2
Unit Test: nUnit 3.7.0
Runner: ReSharper 2019.1

Property stubs on sub mocks aren't working as expected. The stub now has to be set using Mock.Get(mock.Object.Inner) in order for it to work. It was broken in 4.17.1 (works in 4.16.1, did not test in 4.17.0).

public interface IFoo { IBar Bar { get; } }
public interface IBar
{
    string Prop1 { get; }
    string Prop2 { get; set; }
}

[TestFixture]
public class Tests
{
    [Test]
    public void Test()
    {
        const prop2 = "Prop2";
        var mock = new Mock<IFoo>();
        mock.SetupGet(m => m.Bar.Prop1).Returns("Prop1");    // FYI, if this is not included, the setter two lines below throws a NRE. That's also new
                                                             // this just happened to be our particular use case
        mock.SetupProperty(m => m.Bar.Prop2);
        mock.Object.Bar.Prop2 = prop2;
        Assert.AreEqual(prop2, mock.Object.Bar.Prop2);
    }
}
@stakx
Copy link
Member

stakx commented Mar 4, 2022

Thanks for reporting. I'll look into both problems mentioned.

@aaronburro
Copy link
Author

aaronburro commented Mar 4, 2022

Thanks. I suspect they are caused by the same problem.

@stakx stakx added the bug label Mar 6, 2022
@stakx stakx added this to the 4.17.2 milestone Mar 6, 2022
@stakx stakx self-assigned this Mar 6, 2022
@stakx
Copy link
Member

stakx commented Mar 6, 2022

This was indeed a regression... thanks again for reporting it. You were also right that both problems had the same underlying cause. They should be fixed now. An updated version 4.17.2 should become available on NuGet shortly.

@aaronburro
Copy link
Author

aaronburro commented Mar 7, 2022

Those unit tests look suspiciously familiar ;) Thanks for jumping on this.
If you don't mind holding off on 4.17.2 for another day or two, I've got another possible regression around clearing Invocations that happened in 4.15.1. I haven't had a chance to nail down the exact repro steps yet.

@stakx
Copy link
Member

stakx commented Mar 7, 2022

@aaronburro, 4.17.2 is already out there; but worry not, there are plenty more version numbers, so please keep reporting issues if you find any more.

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