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

SetUpAllProperties does not provide stubbing behavior for virtual properties. #283

Closed
apeneve opened this issue Aug 25, 2016 · 1 comment

Comments

@apeneve
Copy link

apeneve commented Aug 25, 2016

I have a simple public virtual string Foo {get;set;} on my class to be mocked.
The mocked object does not remember the value I pass in via mock.Object.Foo = "bar"; even after i call mock.SetUpAllProperties().

As far as I can tell this used to work in an older version. Isn't "stubbing" or "property behavior" supposed to work with virtual properties?

@stakx
Copy link
Contributor

stakx commented Jun 20, 2017

Do you mean something like the following?

[Fact]
public static void MockRemembersPropertyValue()
{
    var mock = new Mock<C>();
    mock.SetupAllProperties();
    mock.Object.Foo = "bar";
    Assert.Equal("bar", mock.Object.Foo);
}

public class C
{
    public virtual string Foo { get; set; }
}

This test passes in the current version of Moq (4.7.49).

If I misunderstood your scenario, please report back with a small but complete repro code and an indication of which version of Moq you're using. In the meantime, I am closing this issue as "non-reproducible error".

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

No branches or pull requests

2 participants