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

Setting multiple indexed objects' property directly via Linq fails #314

Closed
TylerBrinkley opened this issue Jan 3, 2017 · 4 comments
Closed
Milestone

Comments

@TylerBrinkley
Copy link

Consider the following unit tests. I expect the first test to pass but it doesn't so I must use the second's syntax in order for it to pass. Is there some technical limitation that prevents us from using the first test's syntax or can this be fixed in an update?

public class GivenAnIndexer
{
    [Fact]
    public void WhenQueryingWithTwoIndexes_ThenSetsThemDirectly1()
    {
        var foo = Mock.Of<IFoo>(x => x[0].Value == "hello" && x[1].Value == "goodbye");

        Assert.Equal("hello", foo[0].Value); // Fails here as foo[0] is the same object as foo[1] and foo[1].Value == "goodbye"
        Assert.Equal("goodbye", foo[1].Value);
    }

    [Fact]
    public void WhenQueryingWithTwoIndexes_ThenSetsThemDirectly2()
    {
        var foo = Mock.Of<IFoo>(x => x[0] == Mock.Of<IBar>(b => b.Value == "hello") && x[1] == Mock.Of<IBar>(b => b.Value == "goodbye"));

        Assert.Equal("hello", foo[0].Value); // These pass no problem
        Assert.Equal("goodbye", foo[1].Value);
    }

    public interface IFoo
    {
        IBar this[int index] { get; }
    }

    public interface IBar
    {
        string Value { get; }
    }
}
@kzu
Copy link
Contributor

kzu commented Jan 8, 2017 via email

@stakx stakx added this to the v4.9.0 milestone Dec 8, 2017
@stakx stakx removed this from the v4.9.0 milestone Feb 26, 2018
@stakx
Copy link
Contributor

stakx commented Jul 13, 2018

Closing this dormant issue, but marking it as "unresolved" so it can be easily found again. Please see #642 for details. If you'd like to pick this up and work on it, please post here briefly and we'll see what we can do!

@stakx stakx closed this as completed Jul 13, 2018
@stakx stakx added this to the 4.11.0 milestone Sep 5, 2019
@stakx
Copy link
Contributor

stakx commented Sep 5, 2019

@TylerBrinkley, in case you're still tracking this, it has been fixed back in Moq 4.11.0.

P.S.: Added your tests to the regression test suite.

@TylerBrinkley
Copy link
Author

@stakx That's great news. Thanks!

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

No branches or pull requests

3 participants