Fix Issue #328 #9

Merged
merged 1 commit into from Jun 18, 2012

Projects

None yet

3 participants

@yorah
yorah commented Jun 15, 2012

Make Mock.Of work on properties with non-public setters

@yorah
yorah commented Jun 15, 2012

Actually, the issue I encountered was not related to internal members, but to property protected setters, like:

public string MyProperty { get; protected set; }

The real fix to this issue is accomplished by passing true to GetSetMethod, so that it also looks for non-public methods (protected being non-public, as you can guess 😄).

However, as you say, the line I changed in CanOverride (adding !method.IsAssembly) will surely affect internal members and prevent them from working even with InternalsVisibleTo. I will look into it tomorrow, and rollback this particular changes if it indeed introduces a regression!

@yorah
yorah commented Jun 16, 2012

@danielkzu I just updated the PR so that it should keep working with internal members. Nice catch!

@kzu
Member
kzu commented Jun 18, 2012

Looks good! Thanks!

@kzu kzu merged commit cff47ed into moq:master Jun 18, 2012
@Haacked
Haacked commented Jun 19, 2012

Was just about to report this. Has this been pushed to NuGet yet?

@kzu
Member
kzu commented Jun 19, 2012

Nop, pushed to github yes. I'll try to push to nuget by the end of the week

/kzu from mobile
On Jun 19, 2012 7:14 PM, "Phil Haack" <
reply@reply.github.com>
wrote:

Was just about to report this. Has this been pushed to NuGet yet?


Reply to this email directly or view it on GitHub:
#9 (comment)

@Haacked
Haacked commented Jun 19, 2012

Ok, there's still a bug in here. The following test fails. I think your tests pass because the class you're testing is in the same class as the test method. in this case, I made the class I'm testing in a separate class and this fails.

    public class Foo
    {
        protected Foo()
        {
        }

        public virtual string Value { get; private set;}
    }

    public class FooFixture
    {
        [Fact]
        public void Test()
        {
            var remote = Mock.Of<Foo>(rt => rt.Value == "foo");
            Assert.Equal("foo", remote.Value);

        }
    }
@Haacked
Haacked commented Jun 19, 2012

Note that it fails if I remove the protected ctor in Foo too.

@Haacked
Haacked commented Jun 19, 2012

This is weird. Running this in the the debugger shows that the method set_Value(System.String) is not virtual.

@kzu
Member
kzu commented Jun 19, 2012

It's private, so it makes sense...

/kzu from mobile
On Jun 19, 2012 7:38 PM, "Phil Haack" <
reply@reply.github.com>
wrote:

This is weird. Running this in the the debugger shows that the method
set_Value(System.String) is not virtual.


Reply to this email directly or view it on GitHub:
#9 (comment)

@Haacked
Haacked commented Jun 19, 2012

Ah right. But the getter should still be overriden. I opened issue #14 with the problem.

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