Skip to content

Add unit tests for DisposableEvent (void and generic types)#27

Merged
Hissal merged 5 commits into
mainfrom
copilot/add-disposableevent-tests
Dec 15, 2025
Merged

Add unit tests for DisposableEvent (void and generic types)#27
Hissal merged 5 commits into
mainfrom
copilot/add-disposableevent-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 15, 2025

The non-generic DisposableEvent class lacked test coverage, and the generic DisposableEvent<T> class was missing some tests. Added comprehensive test suite covering all public APIs and edge cases for both types.

Changes Made

  1. VoidDisposableEventTest.cs - 12 tests for non-generic DisposableEvent:

    • Uses IEventHandler<Void>[] handlers array with NSubstitute mocks
    • Covers: Publish behavior, subscription disposal, ClearHandlers, Dispose, HandlerCount tracking (including incremental changes), IsDisposed, SnapshotHandlers
    • Mirrors the test patterns from the generic DisposableEventTest
  2. DisposableEventTest.cs - Enhanced with 2 additional tests:

    • HandlerCount_IncrementsWithEachSubscription - validates handler count increases as subscriptions are added
    • HandlerCount_DecrementsWhenSubscriptionDisposed - validates handler count decreases as subscriptions are disposed

Test Patterns

Both test files now follow consistent patterns:

  • sut naming convention for the system under test
  • AAA (Arrange, Act, Assert) structure
  • xUnit + FluentAssertions + NSubstitute stack
  • MethodName_Scenario_ExpectedBehavior naming convention
  • NSubstitute mock handlers with Received()/DidNotReceive() verification
  • Assert.All for collection assertions

Testing

  • ✅ All 313 tests pass successfully on .NET 8 and .NET 9
  • ✅ Code review passed with no issues
  • ✅ Security scan passed with no vulnerabilities

The changes ensure both the generic and non-generic DisposableEvent classes have comprehensive, consistent test coverage.

Original prompt

This section details on the original issue you should resolve

<issue_title>DisposableEvent tests</issue_title>
<issue_description>Unit tests for non generic DisposableEvent (the void type)</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 15, 2025 21:04
Co-authored-by: Hissal <89788928+Hissal@users.noreply.github.com>
Co-authored-by: Hissal <89788928+Hissal@users.noreply.github.com>
Co-authored-by: Hissal <89788928+Hissal@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for DisposableEvent void type Add unit tests for non-generic DisposableEvent (void type) Dec 15, 2025
Copilot AI requested a review from Hissal December 15, 2025 21:11
Copy link
Copy Markdown
Owner

@Hissal Hissal left a comment

Choose a reason for hiding this comment

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

Check the file for the generic typed DisposableEvent tests and mirror how those are substituted and checked.

Also add missing tests to the generic event that have been added to the void one such as the incremental handlercount tests.

Co-authored-by: Hissal <89788928+Hissal@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 15, 2025

Check the file for the generic typed DisposableEvent tests and mirror how those are substituted and checked.

Also add missing tests to the generic event that have been added to the void one such as ...

Updated VoidDisposableEventTest to mirror the generic DisposableEventTest pattern using IEventHandler<Void>[] handlers array with NSubstitute mocks and Assert.All assertions. Also added the two missing incremental HandlerCount tests to DisposableEventTest. Both test files now have 12 tests each with consistent patterns. All 313 tests pass. (commit a582091)

Copilot AI changed the title Add unit tests for non-generic DisposableEvent (void type) Add unit tests for DisposableEvent (void and generic types) Dec 15, 2025
Copilot AI requested a review from Hissal December 15, 2025 21:42
Copy link
Copy Markdown
Owner

@Hissal Hissal left a comment

Choose a reason for hiding this comment

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

lgtm

@Hissal Hissal marked this pull request as ready for review December 15, 2025 22:03
@Hissal Hissal merged commit 0a3d45a into main Dec 15, 2025
2 checks passed
@Hissal Hissal deleted the copilot/add-disposableevent-tests branch December 15, 2025 22:05
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.

DisposableEvent tests

2 participants