Skip to content

Conversation

@logiclrd
Copy link
Contributor

@logiclrd logiclrd commented Oct 1, 2025

This PR:

  • Adds support for ignoring members marked [XmlIgnore].
  • Adds support for ignoring members marked [IgnoreDataMember].
  • Adds support for ignoring fields marked [NonSerialized].
  • Adds tests that exercise these kinds of types with respect to .Should().BeXmlSerializable() and .Should().BeDataContractSerializable().
  • Makes the tests pass by correcting the behaviour of .BeXmlSerializable() and .BeDataContractSerializable() using the new infrastructure.
  • Documents everything.
  • Updates the API surface description.

The first three changes are very similar to one another.

I haven't yet created an issue for the API changes.

Closes: #2626
Closes: #3108

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • 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.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

CONTRIBUTOR LICENSE GRANT

By submitting this contribution, the contributor hereby irrevocably grants to the project owners and maintainers a perpetual, worldwide, royalty-free, irrevocable license to use, reproduce, modify, distribute, sublicense, and create derivative works of the contribution for any purpose and under any terms, including proprietary licensing.

The contributor waives any moral rights in the contribution to the extent permitted by law and agrees not to assert any claim of authorship or control over the contribution. The contributor represents that they are the sole author of the contribution and that it is provided free of any third-party claims.

The contributor understands and agrees that the maintainers may, at their sole discretion, use, license, or redistribute the contribution as part of any work and under any terms they choose, without further permission or attribution.

  • I have read the Contributor License Grant and accept the conditions
  • I'm interested in a free license for Fluent Assertions and will share my email address through [email protected]

@logiclrd logiclrd changed the title Added support for excluding members marked [XmlIgnore], and updated BeXmlSerializable to use it Add support for members ignored for serialization Oct 1, 2025
@coveralls
Copy link

coveralls commented Oct 1, 2025

Pull Request Test Coverage Report for Build 18471605921

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 6 of 7 (85.71%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.005%) to 97.154%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/ObjectAssertionsExtensions.cs 6 7 85.71%
Totals Coverage Status
Change from base Build 18343240400: -0.005%
Covered Lines: 12826
Relevant Lines: 13046

💛 - Coveralls

@github-actions
Copy link

github-actions bot commented Oct 1, 2025

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

@logiclrd
Copy link
Contributor Author

logiclrd commented Oct 2, 2025

@jnyrup Draft pending #3108?

…roperty.cs and JsonProperty.cs.

Added property ExcludeXmlIgnoredMembers to IEquivalencyOptions.cs. Implemented it in CollectionMemberOptionsDecorator.cs. Implemented it in SelfReferenceEquivalencyOptions.cs.
Added class ExcludeXmlIgnoredMembersRule.cs implementing IMemberSelectionRule testing IMember.IsXmlIgnored.
Updated SelfReferenceEquivalencyOptions.cs to represent ExcludeXmlIgnoredMembers in the enumeration given by the SelectionRules property using an instance of ExcludeXmlIgnoredMembersRule.
Added test When_an_object_is_xml_serializable_and_has_properties_marked_XmlIgnore_it_should_succeed to ObjectAssertionSpecs.BeXmlSerializable.
Updated the implementation of ObjectAssertionsExtensions.BeXmlSerializable to include the .ExcludingXmlIgnoredMembers specification. This fixes test When_an_object_is_xml_serializable_and_has_properties_marked_XmlIgnore_it_should_succeed.
….cs, Property.cs and JsonProperty.cs.

Added property ExcludeNonSerializedFields to IEquivalencyOptions.cs. Implemented it in CollectionMemberOptionsDecorator.cs. Implemented it in SelfReferenceEquivalencyOptions.cs.
Added class ExcludeNonSerializedFieldsRule.cs implementing IMemberSelectionRule testing IMember.IsNonSerialized.
Updated SelfReferenceEquivalencyOptions.cs to represent ExcludeNonSerializedFields in the enumeration given by the SelectionRules property using an instance of ExcludeNonSerializedFieldsRule.
Added test When_an_object_is_binary_serializable_and_has_properties_marked_NonSerialized_it_should_succeed() to ObjectAssertionSpecs.BeDataContractSerializable.
Updated the implementation of ObjectAssertionsExtensions.BeDataContractSerializable to include the .ExcludingXmlIgnoredMembers specification. This fixes test When_an_object_is_binary_serializable_and_has_properties_marked_NonSerialized_it_should_succeed().
…ield.cs, Property.cs and JsonProperty.cs.

Added property ExcludeIgnoredDataMembers to IEquivalencyOptions.cs. Implemented it in CollectionMemberOptionsDecorator.cs. Implemented it in SelfReferenceEquivalencyOptions.cs.
Added class ExcludeIgnoredDataMembersRule.cs implementing IMemberSelectionRule testing IMember.IsIgnoredDataMember.
Updated SelfReferenceEquivalencyOptions.cs to represent ExcludeIgnoredDataMembers in the enumeration given by the SelectionRules property using an instance of ExcludeIgnoredDataMembersRule.
Added test When_an_object_is_not_binary_serializable_and_has_properties_marked_IgnoreDataMember_it_should_succeed to ObjectAssertionSpecs.BeDataContractSerializable.
Removed test When_a_data_contract_serializable_object_doesnt_restore_an_ignored_property_it_should_succeed.
Updated the implementation of ObjectAssertionsExtensions.BeDataContractSerializable to include the .ExcludingIgnoredDataMembers specification. This fixes test When_an_object_is_not_binary_serializable_and_has_properties_marked_IgnoreDataMember_it_should_succeed.
@logiclrd
Copy link
Contributor Author

logiclrd commented Oct 2, 2025

Rebased to resolve merge conflict in releases.md. Took the opportunity to restructure and streamline those changes at the same time.

@jnyrup
Copy link
Member

jnyrup commented Oct 2, 2025

@jnyrup Draft pending #3108?

Exactly.

…s, ExcludingIgnoredDataMembers, IncludingIgnoredDataMembers, ExcludingNonSerializedFields and IncludingNonSerializedFields from SelfReferenceEquivalencyOptions.cs. Removed calls from ObjectAssertionsExtensions.cs.

Removed properties ExcludeXmlIgnoredMembers, ExcludeIgnoredDataMembers and ExcludeNonSerializedFields from IEquivalencyOptions.cs. Updated implementations in SelfReferenceEquivalencyOptions.cs and CollectionMemberOptionsDecorator.cs correspondingly.
Removed the ExcludeXmlIGnoredMembersRule, ExcludeIgnoredDataMembersRule and ExcludeNonSerializedFieldsRule logic from the SelfReferenceEquivalencyOptions.SelectionRules accessor.
Made the IsXmlIgnored, IsIgnoredDataMember and IsNonSerialized properties in IMember internal. Updated the implementations in Field.cs, Property.cs and JsonProperty.cs correspondingly.
Added overloads of ObjectAssertionsExtensions.BeXmlSerializable and ObjectAssertionsExtensions.BeDataContractSerializable that allows EquivalencyOptions to be configured.
Updated unit tests in ObjectAssertionSpecs.BeDataContractSerializable.cs and ObjectAssertionSpecs.BeXmlSerializable.cs to test that the default behaviour fails with ignored members, and that the assertion succeeds if the corresponding IMemberSelectionRule classes are `.Using()`ed.
Updated releases.md and the basicassertions.md documentation page to reflect the new publicly-visible changes.
…zable from IMember. Deleted implementations from Field.cs, Property.cs and JsonProperty.cs.

Deleted types ExcludeXmlIgnoredMembersRule.cs, ExcludeIgnoredDataMembersRule.cs and ExcludeNonSerializedFieldsRule.cs.
Removed tests from ObjectAssentionSpecs depending on these rules.
Updated the objectgraphs.md documentation to include user-side implementations of IMemberSelectionRule providing the same functionality for ExcludeXmlIgnoredMembersRule, ExcludeIgnoredDataMembersRule and ExcludeNonSerializedFieldsRule outside of the FluentAssertions codebase.
…tAssertionSpecs.BeXmlSerializable and ObjectAssertionSpecs.BeDataContractSerializable.

Moved all information about ignored members in the context of XML or Data Contract Serialization to the tips.md documentation age. Left just a one-line reference to it next to the mention of BeXmlSerializable and BeDataContractSerializable in basicassertions.md.
Updated the description of the change in releases.md to track changes in the scope of the PR.
# Conflicts:
#	docs/_pages/releases.md
…ges/serializationignoredmembers.md.

Added an entry to _data/navigation.yml to link to serializationignoredmembers under the Tips & Tricks heading.

[Fact]
public void When_a_data_contract_serializable_object_doesnt_restore_an_ignored_property_it_should_succeed()
public void When_an_object_is_not_binary_serializable_and_has_properties_marked_IgnoreDataMember_and_ExcludeIgnoredDataMembers_is_not_used_it_should_fail()
Copy link
Member

Choose a reason for hiding this comment

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

🔧This and the other test tiles don't make sense anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorted 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't get those titles. There's no support for those attributes, so why would you mention them in the test title.
Also, we don't explicitly use technical names in test titles. The titles need to remain functional.

Copy link
Contributor Author

@logiclrd logiclrd Oct 13, 2025

Choose a reason for hiding this comment

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

The attributes are processed by XML serialization and Data Contract serialization themselves. Their support isn't within FluentAssertions but within the framework.

BeDataContractSerializable.When_an_object_is_not_binary_serializable_and_has_properties_marked_IgnoreDataMember_it_should_fail()

This test verifies the expectation that BeDataContractSerializable fails specifically when you hand an object that is not binary-serializable and which has properties marked [IgnoreDataMember]. This behaviour is baked into the definition of what BeDataContractSerializable is, because of how the underlying DataContract serializer system works. If you present it with that and the assertion doesn't fail, then something is wrong with BeDataContractSerializable. If you give it an object that is not binary-serializable, but doesn't have [IgnoreDataMember], or an object that has fields marked [IgnoreDataMember] but also the type is marked [Serializable], then the assertion isn't expected to fail for that reason.

The names make sense in my brain, but I don't object to changing them. I'm just not sure what would be better names.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, I wasn't fully in context when I was reviewing. In this case, you can use a more generic term like "and has explicitly excluded properties" or something like that.

…tests that exercise BeXmlSerializable and BeDataContractSerializable.
This was referenced Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Allow configuring the equivalency behavior of BeXmlSerializable BeXmlSerializable does not respect XmlIgnoreAttribute

4 participants