-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Extend BooleanAssertions with Implies #1886
Comments
Sorry, I don't get it. |
Which part don't you get?
|
This is where my lack of CS degree shows ;-) |
The api and implementation are both straight forward, but my immediate gut feeling is that it will only be needed/used by a few. If you haven't done it already, you could create |
@jnyrup i will take a look on it and try to make the extension. |
@94sedighi Please wait until the API is approved before opening a PR. |
Albeit a bit of a niche request, I have no issue with this proposal. It doesn't add complexity, so it should be easy to support. |
Alright, then I'll approve the API addition too. public class BooleanAssertions<TAssertions>
{
public AndConstraint<TAssertions> Imply(bool expected, string because = "", params object[] becauseArgs)
} |
Is there a way to extract the expectation variable name? This seems a little odd in the failure message: But IMO the failure message should contain both, like: |
Not currently. |
Ahhm.. @94sedighi I've missed the comment where you "saved" this issue. Sorry :) |
Allright 😉 |
I think we can already use that in this API |
How would you add this argument? public AndConstraint<TAssertions> Imply(bool implicator,
string because = "",
[CallerArgumentExpression("implicator")] string implicatorMessage = "",
params object[] becauseArgs) or public AndConstraint<TAssertions> Imply(bool implicator,
[CallerArgumentExpression("implicator")] string implicatorMessage = "",
string because = "",
params object[] becauseArgs) |
Hmm.. what I can see by now: we have to go with approach 2, because if you pass |
Using approach 2 is also problematic Writing this idiomatic FA code subject.Should().Imply(implicator, "because we want to test the {0}", "failure"); fails with this unexpected message
|
Ok I see. Unfortunately this param has to be optional. What we can do? Can we force users to use this parameter? |
Or maybe this only a documentation issue? |
I think we should stick with the approved API, i.e. not using |
ok.. I am fine with that. |
Ah, I see now. So yes, I agree with @jnyrup |
Description
Add logical implication to the available boolean assertions.
That is,
a.Should().Imply(b)
asserts thata → b
.This would be useful in asserting, for example, that object equality implies hash-code equality without additional logic and a better built-in "because".
Complete minimal example
Looking for something like this.
Note this is logically equivalent to
!a || b
.Additional Information
Also volunteering to add this.
The text was updated successfully, but these errors were encountered: