-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
Add [NotNull] attribute on the Should() method for object assertions #2380
Conversation
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.2.8
with:
upload-result: true Contact Qodana teamContact us at qodana-support@jetbrains.com
|
Pull Request Test Coverage Report for Build 7515208120
💛 - Coveralls |
@@ -277,7 +277,7 @@ private static void ForceEnumeration<T>(T subject, Func<T, IEnumerable> enumerab | |||
/// current <see cref="object"/>. | |||
/// </summary> | |||
[Pure] | |||
public static ObjectAssertions Should(this object actualValue) | |||
public static ObjectAssertions Should([System.Diagnostics.CodeAnalysis.NotNull] this object actualValue) |
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.
Why not add the attribute to all Should()
methods?
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.
That's a very good question! I think we should add the [NotNull] attribute on all Should
methods that return a ReferenceTypeAssertions<,>
. So I started to write a test and noticed that I could not assert parameterInfo.IsDecoratedWith<NotNullAttribute>
, hence #2385. 😄
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.
So I started to write a test and noticed that I could not assert parameterInfo.IsDecoratedWith, hence #2385. 😄
I don't think we need to have tests for that.
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.
Well, at least it was very interesting to dive into all the assertion types, I learnt a lot. And the test is now written anyway, alongside other tests on the Should
methods. But this pull request could also be merged without the tests added in AssertionExtensionsSpecs
and thus without requiring #2385 to also be merged.
Isn't this something that pretends what isn't there? In such a case we can get rid of all |
I'm not entirely sure what you are saying? If you mean that we're kind of pretending that the subject is never |
Ok, then this is just to silence the IDE, right? |
Newer compiler version use such attributes to create warnings. Older version does not. |
Ahh.. thanks for clarification :) |
I have rebased this pull request on top of #2385 because the new specs ( |
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
I just rebased this pull request on the The assertion is now written like this: parameter.GetCustomAttribute<NotNullAttribute>().Should().NotBeNull(); instead of this (which would require #2385 to be merged first): parameter.Should().BeDecoratedWith<NotNullAttribute>(); |
Hi @dennisdoomen , Would you consider releasing this feature soon so we can finally avoid workarounds by mixing the native assertions and fluent assertions in the tests. |
Compelling example: ```csharp [Theory] [InlineData(true)] [InlineData(false)] public void Test1(bool currentUser) { IPrincipal principal = currentUser ? new WindowsPrincipal(WindowsIdentity.GetCurrent()) : new ClaimsPrincipal(); IIdentity? identity = principal.Identity; identity.Should().NotBeOfType<GenericIdentity>(); identity.IsAuthenticated.Should().BeFalse(); } ``` Fixes fluentassertions#1115
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.
Please also update the releases.md
I just added an entry in the release notes under improvements in 6ac05e8. |
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.
Awesome
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.
Noticed that [NotNull]
is not added to these overloads of Should
, but guess it doesn't really matter that much.
AssertionExtensions.cs:168: public static ExecutionTimeAssertions Should(this ExecutionTime executionTime)
AssertionExtensions.cs:753: public static TypeSelectorAssertions Should(this TypeSelector typeSelector)
AssertionExtensions.cs:788: public static MethodInfoSelectorAssertions Should(this MethodInfoSelector methodSelector)
AssertionExtensions.cs:813: public static PropertyInfoSelectorAssertions Should(this PropertyInfoSelector propertyInfoSelector)
AssertionExtensions.cs:865: public static TaskCompletionSourceAssertions<T> Should<T>(this TaskCompletionSource<T> tcs)
AssertionExtensions.cs:894: public static TaskCompletionSourceAssertions Should(this TaskCompletionSource tcs)
When is this planned to be released? |
I think there is no specified date for now :) I assume, that at least this ticket have to be completely addressed: #1677 |
@ITaluone is correct |
Is it possible to release it in an alpha release at the very least? Or are there items in #1677 that you need assistance with that could help speed this along. I very much look forward to taking advantage of the changes in this PR, thanks! |
I just tagged alpha 4. Since it's a pre-release, all bets are off. |
Oopsie. 😖
|
Why not just compiling the latest develop yourself?
|
Compelling example:
Fixes #1115