question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Argument constraint That (or Ignored, or _), when nested deeper in A.CallTo, misreports what's being matched

See original GitHub issue

Found while investigating FakeItEasy - How to verify nested arguments value C#.

Consider this test:

public class NestedThat
{
    public class Dto
    {
        public string Id;
    }

    public interface IService
    {
        void DoIt(Dto dto);
    }

    [Test]
    public void Test()
    {
        var fake = A.Fake<IService>();
        fake.DoIt(new Dto { Id = "some id" });

        A.CallTo(() => fake.DoIt(new Dto { Id = A<string>._ })).MustHaveHappened();
    }
}

The author would expect a passing test, but it fails, which isn’t horrible, since the use of A<string>._ inside the Dto constructor is illegal. However, the failure does not lead the reader to the fact that the use of ._ (and I’m sure any variant of That) is bad. Here’s the output:

Test 'FakeItEasyPlay.NestedThat.Test' failed: FakeItEasy.ExpectationException : 

  Assertion failed for the following call:
    FakeItEasyPlay.NestedThat+IService.DoIt(dto: <Ignored>)
  Expected to find it at least once but found it #0 times among the calls:
    1: FakeItEasyPlay.NestedThat+IService.DoIt(dto: FakeItEasyPlay.NestedThat+Dto)

	at FakeItEasy.Core.FakeAsserter.AssertWasCalled(Func`2 callPredicate, String callDescription, Func`2 repeatPredicate, String repeatDescription)
	at FakeItEasy.Configuration.RuleBuilder.MustHaveHappened(Repeated repeatConstraint)
	at FakeItEasy.AssertConfigurationExtensions.MustHaveHappened(IAssertConfiguration configuration)
	NestedThat.cs(19,0): at FakeItEasyPlay.NestedThat.Test()

In addition to not highlighting the illegal ._, we are misreporting the expected argument to DoIt as being equivalent to A<Dto>._.

It may be difficult (impossible) to throw correct error in all cases, but in this one, where we’re capturing a That constraint to match against a parameter of a different type, I’d hope we’d be able to do something.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Jul 31, 2017

It would be nice to update the analyzer to detect this too.

0reactions
blairconradcommented, Oct 10, 2017

This change has been released as part of FakeItEasy 4.1.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FakeItEasy - How to verify nested arguments value C# ...
I've created FakeItEasy Issue 1177 - Argument constraint That , when nested deeper in A.CallTo , misreports what's being matched to help ...
Read more >
Argument constraints
The incoming argument value of out parameters is ignored when matching calls. The incoming value of an out parameter can't be seen by...
Read more >
Type Constraints - Configuration Language | Terraform
Type constructors are unquoted symbols followed by a pair of parentheses, which contain an argument that specifies more information about the type.
Read more >
Database Error Messages
Cause: The control file name specified on the command line was not recognized. It could be misspelled, or another argument (not identified by...
Read more >
Navigation | Jetpack
Note that the arguments have to be an exact match with the entry's arguments. ... From Navigation 2.4.1 : When deep linking through...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found