-
Notifications
You must be signed in to change notification settings - Fork 286
Analyzer implementation to enhance assertions #6720
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
base: main
Are you sure you want to change the base?
Analyzer implementation to enhance assertions #6720
Conversation
Unknown, | ||
Any, | ||
Count, | ||
WhereAny, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding SingleAny and SingleCount for the .Single()
Linq extension method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this just to add it as part of the enums because, there is no use of it for now in the codebase except if we have an issue that wants the analyzer to check for predicate that uses Single Linq
@Youssef1313 thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant full support of .Single()
in this analyzer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh okay.. please can you provide sample code of how it can be used and the expected suggestion code we want analyzer to give..
just to make sure we are on the same page. thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see a few cases, but I'm not sure if they make sense. In all those cases the thrown exception would change at least in one of the possible failure cases. (And those old assertions are not good to start with.)
That's also why I didn't include those when I initially wrote the issue.
// Expected analyzer suggestion:
//Assert.ContainsSingle(x => x == 1, _enumerable);
// Questionable:
Assert.IsNotNull(_enumerable.Where(x => x == 1).SingleOrDefault());
Assert.IsNotNull(_enumerable.SingleOrDefault(x => x == 1));
// Even more questionable:
Assert.IsNotNull(_enumerable.Where(x => x == 1).Single());
Assert.IsNotNull(_enumerable.Single(x => x == 1));
// Expected analyzer suggestion:
//Assert.DoesNotContain(x => x == 1, _enumerable);
// Questionable:
Assert.IsNull(_enumerable.Where(x => x == 1).SingleOrDefault());
Assert.IsNull(_enumerable.SingleOrDefault(x => x == 1));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…Null and Asset.IsNotNull using Single, SingleOrDefaut, WhereSingle and WhereSingleOrDefualt
This Pull request fixes #6360
This implementation involves changes to the Analyzer to suggest a much cleaner approach to write Assertions that involves the use of Predicate functions. for example
Analyzer will suggest (Expected Behaviour)
Assert.Contains(x => x == 1, _enumerable);
Example 2:
Analyzer will suggest (Expected Behaviour)
Assert.DoesNotContain(x => x == 1, _enumerable);