Comments (5)
After further investigation, this is certainly not an issue with XML serialization, but rather how the assertion process handles equivalency:
As my screenshot shows, ignored members are not set during the deserialization process, and as a result the equivalency will fail. I am currently researching how involved of a change it would be to add support for this. I think the most surgical route would be to update EquivalencyOptions<TExpectation>
to exclude ignored members and the BeXmlSerializable
method to specify this as part of its options:
deserializedObject.Should().BeEquivalentTo(assertions.Subject,
static options => options
.RespectingRuntimeTypes()
.IncludingFields()
.IncludingProperties()
.ExcludeIgnoredMembers());
My biggest remaining question is if this new method should be specific to XML or not as ExcludeXmlIgnoredMembers
for clarity that other serialization methods are not supported.
from fluentassertions.
I think a simpler approach could be to add a custom IMemberSelectionRule
that is based on AllPropertiesSelectionRule
and AllFieldsSelectionRule
and filters out properties and fields marked with the XmlIgnore
attribute.
from fluentassertions.
I'm not sure this is an issue with the process not ignoring members. Based on the code for the BeXmlSerializable
method, it looks like this is working as expected and equivalency is failing:
fluentassertions/Src/FluentAssertions/ObjectAssertionsExtensions.cs
Lines 100 to 121 in 060c463
According to line 107 there, the deserialized object should be equivalent to the subject of the assertion. This, combined with my (albeit severely lacking) understanding of how the equivalency test works, should (currently) fail because the ignored members won't be set in the deserialized object.
@dennisdoomen, can this be assigned to me?
from fluentassertions.
I've defined a unit test to cover this scenario and opened a draft PR to begin working this in full. I simply need guidance on the following to prove as effective as possible on the issue:
- Should this be added to the
EquivalencyOptions
model?- If so:
- What should the name of the method be?
- I recommend
ExcludeXmlIgnoredMembers
.
- I recommend
- Are there any niche references of this that I need to be careful about?
- What should the name of the method be?
- If not:
- How should this be accounted for?
- If so:
- Are there any ecosystem-wide scenarios or goals I need to keep in mind?
- Are there any known gotchas with the
BeXmlSerializable
method? - Is there anything else I should be aware of prior to proceeding?
from fluentassertions.
Is it possible to choose an implementation that also enables BeEquivalentTo
to optionally ignore properties with the XmlIgnoreAttribute
?
from fluentassertions.
Related Issues (20)
- Excluding and Including options should fail when applied on types with value semantics HOT 6
- Compare memberless records by value, others by members HOT 11
- Add support for asserting NaN values HOT 10
- Library is not compatible with .NET MAUI 8.0.6 HOT 4
- Add feature to check if an XElement or XAttribute is absent within the XDocument HOT 28
- Null reference exception when using custom comparer in equivalency options HOT 7
- [Feature]: Multi dimension arrays assertions HOT 10
- WithInnerException<T>() needs the type as a parameter HOT 2
- `Should().BeEquivalentTo` failing for identical objects HOT 3
- FluetntAssertion doesn't work correctly for records HOT 8
- Equivalency assertion option Excluding outputs "value(...<>c__DisplayClass).variableName" in some instances HOT 2
- Add string-option for ignoring newline style HOT 2
- Unexpected default equivalency behaviour with interfaces HOT 3
- ArgumentOutOfRangeException in FluentAssertions.Equivalency.Tracing.StringBuilderTraceWriter.ToString() HOT 8
- FluentAssertions: using a NullorEqual string EqualityComparer still returns a type difference error HOT 2
- [API Proposal]: Allow to assert RegEx matched groups HOT 3
- Use StringSyntaxAttribute to provide IDE support for proper reasons HOT 2
- [API Proposal]: Parsability of strings HOT 18
- Add AllSatisfyOrEmpty for GenericCollection HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentassertions.