Skip to content

test: DRY up ResponseIdValidationServiceTests#1078

Merged
BenjaminMichaelis merged 3 commits into
mainfrom
agents/dry-response-id-validation-tests
May 9, 2026
Merged

test: DRY up ResponseIdValidationServiceTests#1078
BenjaminMichaelis merged 3 commits into
mainfrom
agents/dry-response-id-validation-tests

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

What changed

Refactored ResponseIdValidationServiceTests to eliminate repetitive setup boilerplate across all 9 tests.

Before: Each test created its own MemoryCache and ResponseIdValidationService via two static factory helpers, resulting in a 2-line setup block in every test body.

After: A single _service field is initialized once using the production parameterless constructor (which already creates a bounded MemoryCache with SizeLimit = 10_000). Cleanup is handled via [After(Test)] (TUnit-idiomatic) plus IDisposable/GC.SuppressFinalize to satisfy CA1001/CA1816 analyzers.

Why

  • Removes ~30 lines of repeated setup boilerplate
  • Drops the using Microsoft.Extensions.Caching.Memory import entirely — tests no longer need to know cache configuration details
  • Uses the production constructor, so the SizeLimit is inherently exercised without duplication
  • All 11 tests continue to pass

Replace per-test CreateCache/CreateService helpers and local variables with a shared _service field initialized via the production parameterless constructor. Use [After(Test)] for TUnit-idiomatic cleanup and implement IDisposable with GC.SuppressFinalize to satisfy CA1001/CA1816 analyzers. Removes ~30 lines of repetitive setup boilerplate across 9 tests.
Copilot AI review requested due to automatic review settings May 9, 2026 05:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors ResponseIdValidationServiceTests in the test suite to remove repeated per-test setup while still exercising the production ResponseIdValidationService constructor behavior (including bounded MemoryCache sizing).

Changes:

  • Replaced per-test MemoryCache/service factory setup with a single _service field initialized via the production parameterless constructor.
  • Added test cleanup via [After(Test)] and implemented IDisposable to satisfy disposable-field analyzers.
  • Removed the explicit Microsoft.Extensions.Caching.Memory dependency from the test file.

Comment thread EssentialCSharp.Web.Tests/ResponseIdValidationServiceTests.cs Outdated
Add a _disposed guard to prevent double-dispose of the underlying
MemoryCache, satisfying the framework design guideline that Dispose()
must be callable multiple times without throwing.

The test class already uses the correct TUnit pattern ([After(Test)]
with CA1001 suppressed), so no test changes are needed.
…nseIdValidationServiceTests

TUnit0023 recognizes IDisposable.Dispose() as a valid teardown path alongside [After(Test)].
Using IDisposable directly satisfies both CA1001 (Roslyn) and TUnit0023 with a single,
standard C# pattern — no suppression or TUnit-specific hook needed.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread EssentialCSharp.Web.Tests/ResponseIdValidationServiceTests.cs
@BenjaminMichaelis BenjaminMichaelis merged commit 9a3a1d5 into main May 9, 2026
11 checks passed
@BenjaminMichaelis BenjaminMichaelis deleted the agents/dry-response-id-validation-tests branch May 9, 2026 07:08
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.

2 participants