Skip to content
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

Null checks on delegates #1117

Merged
merged 1 commit into from Aug 18, 2019

Conversation

@jnyrup
Copy link
Collaborator

commented Aug 18, 2019

When asserting on delegates we do not check if the delegate is non-null before invoking it.

FailIfSubjectIsAsyncVoid is changed so it does not run for AsyncFunctionAssertions via a new CanHandleAsync property.
The reason it worked before, was that ExecuteInDefaultSynchronizationContext wrapped an async Task method in a Task method.

Type expectedType = typeof(TException);

Execute.Assertion
.ForCondition(!ReferenceEquals(Subject, null))

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Aug 18, 2019

Member

Isn't there a reverse version of subject is null?

This comment has been minimized.

Copy link
@jnyrup

jnyrup Aug 18, 2019

Author Collaborator

The only exact opposite of p is null is !(p is null).
The closest syntax without a negation operator is p is object.
The difference between the two is that:

  • is null only works on reference types as value types cannot be null.
  • is object also works on value types, as every types inherits object, but is always true and gives a CS0183 warning.

In C# 8 with recursive patterns, you could even write
p is {} x as a shorthand for p is MyClass x.

But I would be happy to replace as many ReferenceEquals(p, null) with p is object/p is null in the code base.

@jnyrup jnyrup merged commit d55545a into fluentassertions:master Aug 18, 2019

1 check passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@jnyrup jnyrup deleted the jnyrup:NullActions branch Aug 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.