Make A<T>.Ignored throw an exception when it is invoked
See original GitHub issueI know, that sounds crazy… but it’s not 😉
A<T>.Ignored
(or its shortcut A<T>._
) is used in call specifications to denote that any value of this argument should be a match. If you have long type names (e.g. IEnumerable<CustomerInvoiceDetailLine>
or something like that), it can be tempting to do this:
var any = A<IEnumerable<CustomerInvoiceDetailLine>>.Ignored;
A.CallTo(() => x.PrintInvoiceDetails(any))....
However, this doesn’t work, because FIE analyzes the expression in A.CallTo
to detect calls to A<T>.Ignored
, and in this case the expression doesn’t contain it. A<T>.Ignored
is not meant to actually be called, only to be analyzed as part of the call specification.
This can be very confusing to many users, so I think A<T>.Ignored
should throw an exception (with a message explaining the problem) when it is invoked. It would be better to be able to detect it at compile time, but I don’t think it’s possible.
(this was inspired by this question about Moq, which has the same issue)
Issue Analytics
- State:
- Created 8 years ago
- Comments:29 (28 by maintainers)
Top GitHub Comments
@Jameskmonger, I was wrong. I thought my superseding PR (#619) was merged, but @thomaslevesque’s original PR (#611) was. The commit is 48dc7682e33a7e666b2ed7bebaf7325863313b75.
The commit appears to be https://github.com/FakeItEasy/FakeItEasy/pull/619/commits/cc0fe00a144f36091a1e59b979fbe4112695020c.