Skip to content

Conversation

@Serg046
Copy link
Contributor

@Serg046 Serg046 commented Oct 30, 2020

…s when the condition is false

IMPORTANT

  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by a new or existing set of unit tests which follow the Arrange-Act-Assert syntax such as is used in this example.
  • If the contribution adds a feature or fixes a bug, please update the release notes, which are published on the website.
  • If the contribution changes the public API the changes needs to be included by running AcceptApiChanges.ps1/AcceptApiChanges.sh.
  • If the contribution affects the documentation, please include your changes in this pull request so the documentation will appear on the website.

Fixes #327

@jnyrup
Copy link
Member

jnyrup commented Oct 30, 2020

@Serg046 You're unstoppable! 👍

I assume this problem also occurs for other assertions in SelfReferencingCollectionAssertions?
E.g. HaveCount which invokes Count() and passe on Subject to FailWith.

@Serg046
Copy link
Contributor Author

Serg046 commented Oct 30, 2020

@jnyrup, yes, I can imagine that this problem exists in many places. I'd materialize the subject right after Should() call somehow so that we don't have the problem at all. But it would be a huge change that should be done separately imo.

Regarding this PR, I am just not sure how many places we should fix here. Because if we now try to find all the places, then add the tests for all of them, and finally decide to materialize the subject on an upper layer, we will just lose our prev. work. Please advise how many places this PR should affect, maybe we just check the whole SelfReferencingCollectionAssertions file for now?

@dennisdoomen dennisdoomen merged commit 9844902 into fluentassertions:develop Oct 31, 2020
@jnyrup
Copy link
Member

jnyrup commented Oct 31, 2020

@Serg046 We avoid doing any tranformations on the input and just store it directly on Subject, such that e.g. value.Should().BeSameAs(value) behaves as expected.

If I understand your proposal, you're suggesting caching the materialized collection on SelfReferencingCollectionAssertions it self, to avoid enumerating the input multiple times even for chained assertions.

myEntityCollection.Should()
    .NotBeEmpty() <-- materialize and cache `Subject`
    .And.Contain(entity) <-- reuse cached collection
    .And.NotContain(otherEntity);  <-- reuse cached collection

That approach sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linq2Sql entity - default value formatter runs into SQL queries

3 participants