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

Custom matcher properties not printed correctly in error messages #516

Closed
stakx opened this issue Nov 6, 2017 · 0 comments
Closed

Custom matcher properties not printed correctly in error messages #516

stakx opened this issue Nov 6, 2017 · 0 comments
Assignees
Labels
Milestone

Comments

@stakx
Copy link
Contributor

stakx commented Nov 6, 2017

Consider this test code:

public interface IChild
{
    void PlayWith(Toy toy);
}

public class Toy
{
    public string Color { get; set; }

    public static Toy ThatIsRed => Match.Create((Toy toy) => toy.Color == "red");
}

[Fact] // does not pass
public void Custom_matcher_property_appears_by_name_in_verification_error_message()
{
    var child = new Mock<IChild>();
    child.Setup(c => c.PlayWith(Toy.ThatIsRed)).Verifiable();

    var ex = Assert.Throws<MockException>(() => child.Verify());

    Assert.Contains(".PlayWith(Toy.ThatIsRed)", ex.Message);
}

The test fails with:

Message: Assert.Contains() Failure
Not found: .PlayWith(Toy.ThatIsRed)
In value:  The following setups were not matched:
IChild c => c.PlayWith(null)

The error message contains "null" instead of the matcher property's name.

@stakx stakx added the bug label Nov 6, 2017
@stakx stakx self-assigned this Nov 6, 2017
@stakx stakx added this to the v4.8.0 milestone Nov 6, 2017
@stakx stakx closed this as completed Nov 6, 2017
@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
Projects
None yet
Development

No branches or pull requests

1 participant