Skip to content

Bug using Mock.Of on objects with virtual properties. #14

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

Closed
haacked opened this issue Jun 19, 2012 · 5 comments · Fixed by #19
Closed

Bug using Mock.Of on objects with virtual properties. #14

haacked opened this issue Jun 19, 2012 · 5 comments · Fixed by #19

Comments

@haacked
Copy link

haacked commented Jun 19, 2012

The pull request #9 attempts to fix this, but there are still a few cases it doesn't work. Append the following code at the end of
QueryableMocksFixture and you'll see the tests fail.

    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);
        }
    }

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

    public class BarFixture
    {
        [Fact]
        public void Test()
        {
            var remote = Mock.Of<IBar>(rt => rt.Foo.Value == "foo");
            Assert.Equal("foo", remote.Foo.Value);
        }
    }
@haacked haacked mentioned this issue Jun 19, 2012
@haacked
Copy link
Author

haacked commented Jun 20, 2012

@yorah any chance you'll look at this? This bug makes the refactoring you did for us on LibGit2 useless to us. :(

@yorah
Copy link
Contributor

yorah commented Jun 20, 2012

@haacked yep, I'll look into this in the coming days. In the meantime, did you try using SetupGet to walk around this bug?

@haacked
Copy link
Author

haacked commented Jun 20, 2012

@yorah The problem is I have a ton of code using Mock.Of. I don't want to rewrite it all, then rewrite it again.

@nulltoken
Copy link

@yorah Thanks for having taken care of this! ❤️

@haacked
Copy link
Author

haacked commented Jun 21, 2012

❤️ ❤️ ❤️

@haacked haacked closed this as completed Dec 18, 2013
@devlooped devlooped locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants