Add overload to `HaveElement()` to be able to assert on occurrences for `XDocument` and `XElement` by ITaluone · Pull Request #1880 · fluentassertions/fluentassertions · GitHub
Skip to content

Add overload to HaveElement() to be able to assert on occurrences for XDocument and XElement#1880

Merged
jnyrup merged 47 commits into
fluentassertions:developfrom
ITaluone:issue-1681
Apr 23, 2022
Merged

Add overload to HaveElement() to be able to assert on occurrences for XDocument and XElement#1880
jnyrup merged 47 commits into
fluentassertions:developfrom
ITaluone:issue-1681

Conversation

@ITaluone

@ITaluone ITaluone commented Apr 5, 2022

Copy link
Copy Markdown
Contributor

This ref. #1681 and #1684
Closes #1681

Try to finish the work of @ABergBN

IMPORTANT

  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.

@coveralls

coveralls commented Apr 5, 2022

Copy link
Copy Markdown

@IT-VBFK

IT-VBFK commented Apr 5, 2022

Copy link
Copy Markdown
Contributor

Maybe using the OccurrenceConstaints for asserting on the expected count?

@ITaluone ITaluone changed the title Implement HaveElementCount() and HaveSingleElement() for XDocument Add overload to HaveElement() to be able to assert on occurrences and add HaveSingleElement() for XDocument Apr 6, 2022
@ITaluone ITaluone marked this pull request as ready for review April 6, 2022 05:33
@jnyrup

jnyrup commented Apr 7, 2022

Copy link
Copy Markdown
Member

It's a bit difficult to review, when the APIs keep changing 😉
You can always mark a PR as draft.

We are trying to formalize the process of changes a bit, such that larger changes are first discussed in an issue before opening a PR.
Typos and alike are always welcome and don't need to go through an issue.

We haven't fully set on the process, but these links should provide a feeling of it, notably excluding the amount of manpower we can allocate.
https://devblogs.microsoft.com/dotnet/api-review-process-for-net-core/
https://github.com/dotnet/runtime/blob/main/docs/project/api-review-process.md

@IT-VBFK

IT-VBFK commented Apr 7, 2022

Copy link
Copy Markdown
Contributor

This PR just finishes an already discussed feature.
The only difference by now is to use the OccurrenceConstraint, which makes more sense IMO

ahh.. and btw. This state is my „final“ change 🙃

@dennisdoomen dennisdoomen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 I leave a code review comment only once and assume that similar code needs similar improvements.
🤔 For consistency, we also need to add those new members to XElementAssertions.

Comment thread Src/FluentAssertions/Xml/XDocumentAssertions.cs Outdated
Comment thread Src/FluentAssertions/Xml/XDocumentAssertions.cs Outdated
Comment thread Src/FluentAssertions/Xml/XDocumentAssertions.cs Outdated
Comment thread Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs
Comment thread Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs Outdated

@jnyrup jnyrup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it seems you like to learn about our process.
You're not "just" continuing another PR when you change the API. ℹ️

The main reason I asked about discussing the API again, was because I like the usage of OccurrenceConstraint and had ideas to improve it even more 🚀

Comment thread Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt Outdated
Comment thread Tests/Approval.Tests/ApprovedApi/FluentAssertions/net47.verified.txt Outdated
@ITaluone ITaluone force-pushed the issue-1681 branch 3 times, most recently from 401ec08 to 5b1ae03 Compare April 8, 2022 04:54
@ITaluone ITaluone changed the title Add overload to HaveElement() to be able to assert on occurrences and add HaveSingleElement() for XDocument Add overload to HaveElement() to be able to assert on occurrences and add HaveSingleElement() for XDocument and XElement Apr 8, 2022
@ITaluone

ITaluone commented Apr 8, 2022

Copy link
Copy Markdown
Contributor Author

@dennisdoomen What do you think: Should I remove the HaveSingleElement() method?

Comment thread Src/FluentAssertions/Xml/XDocumentAssertions.cs Outdated
Comment thread Src/FluentAssertions/Xml/XDocumentAssertions.cs
@dennisdoomen

Copy link
Copy Markdown
Member

HaveSingleElement() reads less "fluent" than HaveElement("x", Exactly.Once());

I have to admit I agree. The only case where it would read fluent if there was a parameterless HaveSingleElement.

@jnyrup

jnyrup commented Apr 16, 2022

Copy link
Copy Markdown
Member

Is the the API change we can agree on?

class XDocumentAssertions
{
+    AndWhichConstraint<XDocumentAssertions, IEnumerable<XElement>> HaveElement(string expected, OccurrenceConstraint occurrenceConstraint, string because = "", params object[] becauseArgs)
+    AndWhichConstraint<XDocumentAssertions, IEnumerable<XElement>> HaveElement(XName expected, OccurrenceConstraint occurrenceConstraint, string because = "", params object[] becauseArgs)
}

class XElementAssertions
{
+    AndWhichConstraint<XElementAssertions, IEnumerable<XElement>> HaveElement(string expected, OccurrenceConstraint occurrenceConstraint, string because = "", params object[] becauseArgs)
+    AndWhichConstraint<XElementAssertions, IEnumerable<XElement>> HaveElement(XName expected, OccurrenceConstraint occurrenceConstraint, string because = "", params object[] becauseArgs)
}

@dennisdoomen

Copy link
Copy Markdown
Member

@dennisdoomen dennisdoomen added the api-approved API was approved, it can be implemented label Apr 16, 2022

@IT-VBFK IT-VBFK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move release notes to the appropriate section

and/or rebase to current develop

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

Labels

api-approved API was approved, it can be implemented feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] - Count XDocument nodes

5 participants