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

ClearExpectation after Given<> always returns false #1596

Closed
eNeRGy164 opened this issue Jun 2, 2021 · 3 comments · Fixed by #1791
Closed

ClearExpectation after Given<> always returns false #1596

eNeRGy164 opened this issue Jun 2, 2021 · 3 comments · Fixed by #1791
Labels

Comments

@eNeRGy164
Copy link
Contributor

eNeRGy164 commented Jun 2, 2021

Description

ClearExpectation() returns false after a successful Given<>.

Complete minimal example reproducing the issue

bool success = Execute.Assertion
    .Given(() => new object())
    .ForCondition(subject => true)
    .FailWith("but collection is <null>.")
    .Then
    .ClearExpectation();

success.Should().BeTrue();

Expected behavior:

Should return true.

Actual behavior:

Returns false

Having another Given(() => {}).ForCondition() chain after ClearExpectation will return true again.

Versions

  • 6.0 beta (source)
  • Any
@eNeRGy164
Copy link
Contributor Author

I'm investigating this and finding all kinds of methods that are not completely following the continuation logic as expected.

Expect incoming unit tests on AssertionScope, ContinuedAssertionScope and GivenSelector 😅

@eNeRGy164
Copy link
Contributor Author

The root cause of this issue is not easily fixable without breaking changes I think.
It comes down to the fact that the return value of an AssertionScope is only reliable if FailWith is the last method in the chain. Every next method can't know the state of the scope as it's an internal value (Nullable<bool>) that is reset after every failure.
Every continuation needs this value as input, but it's not queryable as it is immediately reset to null.
That means that ClearExpectation needs to know if the chain is in a failure or successful flow, the scope status will be null. This could be seen as successful (not false, so no failure), but that would also mean it can't return false when it was actually preceded by a failure.

@dennisdoomen
Copy link
Member

Then I'll need to dive into this when I have time again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants