Sitelet https://github.com/fluentassertions/fluentassertions/pull/3295
Skip to content

Fix exception on HaveProperty on JsonArray - #3295

Merged
jnyrup merged 2 commits into
mainfrom
Json_cleanup
Aug 10, 2026
Merged

jnyrup merged 2 commits into
mainfrom
Json_cleanup

Conversation

@jnyrup

@jnyrup jnyrup commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

When HaveProperty is called on a non-JsonObject, e.g. JsonArray, and the assertion is wrapped in an AssertionScope, we would try to lookup the property on the JsonArray, which throws and InvalidOperationException.

The second commit is purely cleaup

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 sales@xceed.com

@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Test Results

    37 files  ±0      37 suites  ±0   2m 47s ⏱️ -16s
 6 424 tests +1   6 423 ✅ +1  1 💤 ±0  0 ❌ ±0 
39 890 runs  +6  39 884 ✅ +6  6 💤 ±0  0 ❌ ±0 

Results for commit 6420992. ± Comparison against base commit f4026e7.

This pull request removes 10 and adds 9 tests. Note that renamed tests count towards both.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HaveLength ‑ When_a_throwing_stream_should_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HaveLength ‑ When_a_throwing_stream_should_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HavePosition ‑ When_a_throwing_stream_should_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HavePosition ‑ When_a_throwing_stream_should_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHaveLength ‑ When_a_throwing_stream_should_not_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHaveLength ‑ When_a_throwing_stream_should_not_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHavePosition ‑ When_a_throwing_stream_should_not_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHavePosition ‑ When_a_throwing_stream_should_not_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetLengthExceptionMessage'.)
Object name: 'GetPositionExceptionMessage'.)
FluentAssertions.Specs.Specialized.JsonNodeSpecs+HaveProperty ‑ Arrays_do_not_have_properties
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HaveLength ‑ When_a_throwing_stream_should_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetLengthExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HaveLength ‑ When_a_throwing_stream_should_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetLengthExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HavePosition ‑ When_a_throwing_stream_should_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetPositionExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+HavePosition ‑ When_a_throwing_stream_should_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetPositionExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHaveLength ‑ When_a_throwing_stream_should_not_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetLengthExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHaveLength ‑ When_a_throwing_stream_should_not_have_a_length_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetLengthExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHavePosition ‑ When_a_throwing_stream_should_not_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetPositionExceptionMessage'.)
FluentAssertions.Specs.Streams.StreamAssertionSpecs+NotHavePosition ‑ When_a_throwing_stream_should_not_have_a_position_it_should_fail(exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'GetPositionExceptionMessage'.)

♻️ This comment has been updated with latest results.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 31315276389

Coverage increased (+0.04%) to 97.199%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: Could not be determined — this PR's diff is too large for GitHub to return (406 error at GitHub).
  • 1 coverage regression across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
Src/FluentAssertions/Specialized/JsonNodeAssertions.cs 1 96.49%

Coverage Stats

Coverage Status
Relevant Lines: 13436
Covered Lines: 13211
Line Coverage: 98.33%
Relevant Branches: 4376
Covered Branches: 4102
Branch Coverage: 93.74%
Branches in Coverage %: Yes
Coverage Strength: 69224.02 hits per line

💛 - Coveralls

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

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 qodana-support@jetbrains.com

@jnyrup jnyrup changed the title Fix exception on HaveProperty on JsonArray Fix exception on HaveProperty on JsonArray Aug 9, 2026
@jnyrup
jnyrup requested a review from dennisdoomen August 9, 2026 13:36
Comment thread Tests/FluentAssertions.Specs/Specialized/JsonNodeSpecs.cs
@jnyrup
jnyrup merged commit cb6183a into main Aug 10, 2026
17 of 18 checks passed
@jnyrup
jnyrup deleted the Json_cleanup branch August 10, 2026 06:57
This was referenced Sep 14, 2026
This was referenced Oct 2, 2026

This branch was previously deployed

1 inactive deployment
qodana-pr — 64209924 Deployed Aug 9, 2026 by jnyrup via Qodana Scan #62
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 this pull request may close these issues.

3 participants