False positive "nested constraint" exception when using an argument constraint of the wrong type
See original GitHub issueOriginal title: Weird issue with nested constraints and simple types
public interface IEmailFactory
{
Task<IList<MailMessage>> GetEmailMessages(long idPairGame, EmailTemplateType emailTemplateType);
}
_emailFactory = new Fake<IEmailFactory>().FakedObject;
A.CallTo(() => _emailFactory.GetEmailMessages(A<int>._, A<EmailTemplateType>._)).Returns(mailMessages);
EmailTemplateType is an enum. When I change it to int it is still wrong, so it is not an issue.
FakeIt version 4.1.
It throws the following exception
FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.ArgumentConstraintExpressionVisitor.VisitMember(MemberExpression node) at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node) at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor) at FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.CheckArgumentExpressionIsValid(Expression expression) at FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.GetArgumentConstraintFromExpression(Expression expression, Object& value) at FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.GetArgumentConstraint(ParsedArgumentExpression argument) at System.Linq.Utilities.<>c__DisplayClass2_0
3.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectEnumerableIterator
2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at FakeItEasy.Expressions.ExpressionCallMatcher..ctor(ParsedCallExpression parsedExpression, ExpressionArgumentConstraintFactory constraintFactory, MethodInfoManager methodInfoManager, Factory outputWriterFactory) at FakeItEasy.RootModule.<>c__DisplayClass0_0.<RegisterDependencies>b__4(ParsedCallExpression callSpecification) at FakeItEasy.Configuration.FakeConfigurationManager.CallTo[T](Expression
1 callSpecification)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:15 (11 by maintainers)
Top GitHub Comments
This change has been released as part of FakeItEasy 4.1.1.
Thanks for the report @progala2! Look for your name in the release notes. 🏆
There’s a problem in your code: it should be
A<long>._
, notA<int>._
. Since the parameter is of type long, theA<int>._
constraint will never match; in fact, we even added a diagnostic in the latest analyzer.I think this is what causing the error, since I can’t reproduce the problem when I change the constraint type. However, the exception is clearly incorrect, we definitely have a bug.