Skip to content

Add unit tests for MerchantRequestHandler to achieve ~100% coverage#790

Merged
StuartFerguson merged 4 commits intomainfrom
copilot/add-merchant-request-handler-tests
Feb 24, 2026
Merged

Add unit tests for MerchantRequestHandler to achieve ~100% coverage#790
StuartFerguson merged 4 commits intomainfrom
copilot/add-merchant-request-handler-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 23, 2026

MerchantRequestHandler had no unit test coverage. This PR adds 38 tests covering all 17 handler methods.

Coverage

  • 8 queries: GetMerchants, GetMerchant, GetRecentMerchants, GetMerchantKpi, GetMerchantsForDropDown, GetMerchantContracts, GetMerchantOperators, GetMerchantDevices — success + failure per method
  • 8 commands: AddMerchantDevice, AddOperatorToMerchant, CreateMerchant, MakeMerchantDeposit, RemoveContractFromMerchant, RemoveOperatorFromMerchant, SwapMerchantDevice, AssignContractToMerchant — success + failure per method
  • UpdateMerchantCommand: 4 cases covering the sequential call chain — full success, and early-exit failure at each of UpdateMerchant, UpdateMerchantAddress, and UpdateMerchantContact
[Fact]
public async Task Handle_UpdateMerchantCommand_ReturnsFailure_WhenUpdateMerchantAddressFails()
{
    // UpdateMerchant succeeds, UpdateMerchantAddress fails → contact call never made
    _mockApiClient.Setup(c => c.UpdateMerchant(command, It.IsAny<CancellationToken>()))
        .ReturnsAsync(Result.Success());
    _mockApiClient.Setup(c => c.UpdateMerchantAddress(command, It.IsAny<CancellationToken>()))
        .ReturnsAsync(Result.Failure("update address failed"));

    var result = await _handler.Handle(command, CancellationToken.None);

    result.IsFailed.ShouldBeTrue();
    _mockApiClient.Verify(c => c.UpdateMerchantContact(command, It.IsAny<CancellationToken>()), Times.Never);
}

Tests follow the existing DateRequestHandlerTests conventions (Moq + Shouldly).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet test EstateManagementUI.BlazorServer.Tests/EstateManagementUI.BlazorServer.Tests.csproj --filter FullyQualifiedName~MerchantRequestHandlerTests (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.0/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.0/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/EstateManagementUI/EstateManagementUI/EstateManagementUI.sln --packages /home/REDACTED/work/EstateManagementUI/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/EstateManagementUI/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/EstateManagementUI/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>MerchantRequestHandler Unit Tests</issue_title>
<issue_description>Ensure a good level of code coverage as close to 100% as possible</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 changed the title [WIP] Add unit tests for MerchantRequestHandler to improve code coverage Add unit tests for MerchantRequestHandler to achieve ~100% coverage Feb 23, 2026
Copilot AI requested a review from StuartFerguson February 23, 2026 21:21
@StuartFerguson StuartFerguson marked this pull request as ready for review February 24, 2026 09:38
@StuartFerguson StuartFerguson merged commit a87e3d3 into main Feb 24, 2026
10 checks passed
@github-actions github-actions Bot deleted the copilot/add-merchant-request-handler-tests branch April 26, 2026 01:23
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.

MerchantRequestHandler Unit Tests

2 participants