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

Already on GitHub? Sign in to your account

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

Closed
Haacked opened this Issue Jun 19, 2012 · 5 comments

Comments

Projects
None yet
3 participants

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 referenced this issue Jun 19, 2012

Merged

Fix Issue #328 #9

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. :(

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 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.

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

Haacked commented Jun 21, 2012

❤️ ❤️ ❤️

@Haacked Haacked closed this Dec 18, 2013

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