Skip to content

refactor(mocks): extract MockTypeModel.Visibility helper#5443

Merged
thomhurst merged 1 commit intomainfrom
fix/5426-cleanup
Apr 7, 2026
Merged

refactor(mocks): extract MockTypeModel.Visibility helper#5443
thomhurst merged 1 commit intomainfrom
fix/5426-cleanup

Conversation

@thomhurst
Copy link
Copy Markdown
Owner

Summary

  • Follow-up cleanup to [Bug]: CS9338 for interface mock when interface is not public #5426 fix (commit 53bd350 on main).
  • Extracts a single Visibility property on MockTypeModel to replace the duplicated IsPublic ? "public" : "internal" ternary across five builders.
  • Restores the optional defaults on spanReturnElementType / spanReturnType in GenerateVoidUnifiedClass by moving the visibility parameter earlier in the signature (it had been demoted to required to make room for the new param).

Test plan

  • TUnit.Mocks.Tests builds clean
  • Issue5426Tests (3/3) pass

Replaces the duplicated 'IsPublic ? "public" : "internal"' ternary
across five builders with a single Visibility property on MockTypeModel.
Also restores the optional defaults on spanReturnElementType/spanReturnType
in GenerateVoidUnifiedClass by moving the new visibility parameter earlier
in the signature.
Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Code Review

Clean, well-scoped refactor. No issues found.

What this does well

DRY principle applied correctly — the duplicated model.IsPublic ? "public" : "internal" ternary appeared in 5 separate builders, all computing the same value from the same source. Extracting it to MockTypeModel.Visibility is the right place for this logic: the model owns the data, so the derived string belongs there too.

Signature fix in GenerateVoidUnifiedClass — moving visibility to an earlier position in the parameter list was necessary to restore the optional defaults on spanReturnElementType / spanReturnType. C# requires that parameters with defaults trail all required parameters, so the previous ordering was forcing callers to always pass nulls explicitly. The reordering is correct and improves call-site ergonomics.

Minimal footprint — the PR touches exactly the right files and nothing more. The XML doc comment on Visibility is concise and useful.

Minor notes (no action needed)

  • IsPublic is still present on the model (correctly, as the source of truth). Visibility is a purely derived helper — that separation is appropriate.
  • If visibility ever needs to support more than two states (e.g., protected internal), this is the one place to update — a good consolidation point.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@thomhurst thomhurst enabled auto-merge (squash) April 7, 2026 18:15
@thomhurst thomhurst linked an issue Apr 7, 2026 that may be closed by this pull request
1 task
@thomhurst thomhurst merged commit 1be83c3 into main Apr 7, 2026
15 checks passed
@thomhurst thomhurst deleted the fix/5426-cleanup branch April 7, 2026 18:33
This was referenced Apr 7, 2026
This was referenced Apr 10, 2026
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.

[Bug]: CS9338 for interface mock when interface is not public

1 participant