Argument constraint That (or Ignored, or _), when nested deeper in A.CallTo, misreports what's being matched
See original GitHub issueFound 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:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be nice to update the analyzer to detect this too.
This change has been released as part of FakeItEasy 4.1.0.