Skip to content

Feature: Add unit tests#6

Merged
ambvdijk merged 14 commits intodevelopfrom
feature/add-unit-tests
Jul 9, 2025
Merged

Feature: Add unit tests#6
ambvdijk merged 14 commits intodevelopfrom
feature/add-unit-tests

Conversation

@ambvdijk
Copy link
Copy Markdown
Collaborator

@ambvdijk ambvdijk commented Jul 8, 2025

No description provided.

ambvdijk and others added 7 commits July 8, 2025 11:02
…projects. (#2)

* Create codeql.yml

* Update CodeQL workflow to use .NET 9.0.x

Changed the dotnet-version in the CodeQL GitHub Actions workflow from 8.0.x to 9.0.x to align with the project's SDK requirements.

* Set fetch-depth to 0 in CodeQL workflow

Updated the checkout step in the CodeQL workflow to use 'fetch-depth: 0', ensuring the full git history is available for analysis.
Updated dotnet and sonarqube GitHub Actions workflows to trigger on both main and develop branches for push and pull request events. This ensures CI processes run for changes targeting the develop branch.
The build step in the GitHub Actions workflow now runs 'dotnet build' without the '--no-restore' flag, ensuring dependencies are restored during the build process.
* Remove --no-restore from dotnet build step

The build step in the GitHub Actions workflow now runs 'dotnet build' without the '--no-restore' flag, ensuring dependencies are restored during the build process.

* Update dotnet.yml
Introduces a dependabot.yml file to enable automated weekly updates for NuGet dependencies in the repository.
Introduces a modular and SOLID-compliant test suite for CommandHandlerBase, including constructor validation, edge case, and shared test infrastructure. Adds new test classes, helpers, and a detailed README describing the new structure. Also adds Moq as a test dependency.
Introduces tests covering core functionality of the HandleAsync method in CommandHandlerBase, including event envelope creation, ULID generation, timestamp handling, serialization, storage, and abstract method calls.
@ambvdijk ambvdijk requested a review from Copilot July 8, 2025 17:53
Switch SonarQube workflow from Windows to Ubuntu, update path separators for Unix compatibility, and remove PowerShell-specific commands. Minor formatting improvements were made to the dotnet workflow for consistency.
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

This PR introduces a comprehensive suite of unit tests for the CommandHandlerBase<TCommand, TEvent> class, refactors test infrastructure for better maintainability, and updates CI workflows to run tests on the develop branch.

  • Adds Moq as a test dependency in the test project’s csproj.
  • Introduces shared test fixtures, helper classes, and three focused test classes covering constructor validation, core HandleAsync functionality, and edge cases.
  • Updates GitHub Actions workflows to include the develop branch and adjusts build steps.

Reviewed Changes

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

Show a summary per file
File Description
MathMax.EventSourcing.UnitTests/MathMax.EventSourcing.UnitTests.csproj Adds Moq package reference for mocking dependencies in tests.
MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/TestHelpers.cs Defines test commands/events and concrete/spy handlers for testing.
MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/README.md Documents the refactored test architecture and guidelines.
MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/CommandHandlerBaseTestFixture.cs Provides shared mocks, factories, and verification helpers.
MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/CommandHandlerBaseConstructorTests.cs Validates constructor parameter checks and exception behavior.
MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/CommandHandlerBaseHandleAsyncTests.cs Tests core HandleAsync behavior, ULID generation, and serialization/storage.
MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/CommandHandlerBaseEdgeCaseTests.cs Covers null‐aggregate‐ID, null‐version, and event type name edge cases.
.github/workflows/sonarqube.yml Includes develop branch in SonarQube analysis triggers.
.github/workflows/dotnet.yml Runs build and test jobs on both main and develop branches.
Comments suppressed due to low confidence (2)

MathMax.EventSourcing.UnitTests/Commands/CommandHandlerBase/CommandHandlerBaseEdgeCaseTests.cs:32

  • Add a verification step (e.g., dependencies.VerifySerializationAndStorage(...)) after this assertion to ensure the serializer and event store were still called for the null-aggregate-ID scenario.
        Assert.Null(result.AggregateId);

.github/workflows/dotnet.yml:30

  • Reintroduce the --no-restore flag on dotnet build --no-restore to avoid redundant package restore and speed up the CI build.
      run: dotnet build

Comment thread MathMax.EventSourcing.UnitTests/MathMax.EventSourcing.UnitTests.csproj Outdated
ambvdijk and others added 6 commits July 8, 2025 19:57
Adds setup for .NET 9.0, configures SonarQube scanner to use OpenCover reports, and updates test command to collect code coverage in OpenCover format. These changes improve code analysis and ensure compatibility with the latest .NET version.
…s.csproj

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Changed CreateTestCommand to a static method in CommandHandlerBaseTestFixture for easier access without instantiation. Updated a test in CommandHandlerBaseConstructorTests to use Assert.IsType with exactMatch: false instead of Assert.IsAssignableFrom.
Replaced usage of _fixture.CreateTestCommand() with CommandHandlerBaseTestFixture.CreateTestCommand() in CommandHandlerBaseEdgeCaseTests and CommandHandlerBaseHandleAsyncTests for consistency and clarity.
Split TestHelpers.cs into individual files for each test class: TestCommand, TestEvent, TestCommandHandler, SpyTestCommandHandler, TestCommandHandlerWithNullAggregateId, and TestCommandHandlerWithNullVersion. This improves code organization and maintainability.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jul 9, 2025

@ambvdijk ambvdijk merged commit 9b52864 into develop Jul 9, 2025
5 checks passed
@ambvdijk ambvdijk deleted the feature/add-unit-tests branch July 9, 2025 19:17
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