Skip to content

Add missing test coverage for MerchantStatementDomainService#1541

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/update-test-coverage-merchant-statement
Feb 23, 2026
Merged

Add missing test coverage for MerchantStatementDomainService#1541
StuartFerguson merged 3 commits intomasterfrom
copilot/update-test-coverage-merchant-statement

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 23, 2026

Each method in MerchantStatementDomainService lacked tests for aggregate fetch failures, save failures, and unhandled exceptions — leaving entire error-handling branches uncovered.

Added test cases

  • AddTransactionToStatementMerchantStatementForDateAggregate fetch failure; exception thrown
  • AddSettledFeeToStatementMerchantStatementForDateAggregate fetch failure; exception thrown
  • AddDepositToStatementMerchantStatementForDateAggregate fetch failure; save failure; exception thrown
  • AddWithdrawalToStatementMerchantStatementForDateAggregate fetch failure; save failure; exception thrown
  • RecordActivityDateOnMerchantStatementMerchantStatementAggregate fetch failure; exception thrown
  • GenerateStatementMerchantStatementAggregate fetch failure; exception thrown
  • BuildStatementMerchantStatementAggregate fetch failure; IStatementBuilder.GetStatementHtml failure; exception thrown
  • EmailStatementMerchantStatementAggregate fetch failure; save failure; exception thrown

Each test follows the existing Moq/Shouldly/TestData conventions. Failure-path tests use ReturnsAsync(Result.Failure()) and exception tests use .ThrowsAsync(new Exception("Test exception")), asserting result.IsFailed.ShouldBeTrue() in both cases:

[Fact]
public async Task MerchantStatementDomainService_AddDepositToStatement_ExceptionThrown_ResultIsFailed()
{
    this.AggregateService
        .Setup(a => a.GetLatest<MerchantStatementForDateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
        .ThrowsAsync(new Exception("Test exception"));

    Result result = await this.DomainService.AddDepositToStatement(
        TestData.Commands.AddDepositToMerchantStatementCommand, CancellationToken.None);

    result.IsFailed.ShouldBeTrue();
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Update Test Coverage on Merchant Statement Domain service</issue_title>
<issue_description>Each domain service method needs new tests added to cover all cases</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.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
@StuartFerguson StuartFerguson marked this pull request as ready for review February 23, 2026 13:55
Copilot AI changed the title [WIP] Update test coverage on merchant statement domain service Add missing failure-path test coverage for MerchantStatementDomainService Feb 23, 2026
Copilot AI requested a review from StuartFerguson February 23, 2026 13:57
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot can you add exception cases to the tests for each method

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

Copilot AI commented Feb 23, 2026

@copilot can you add exception cases to the tests for each method

Added exception test cases for all 8 methods in commit 9059e68. Each test configures the first mock call to ThrowsAsync(new Exception("Test exception")) and asserts result.IsFailed.ShouldBeTrue(), verifying the catch (Exception ex) block in each method returns Result.Failure.

Copilot AI changed the title Add missing failure-path test coverage for MerchantStatementDomainService Add missing test coverage for MerchantStatementDomainService Feb 23, 2026
@StuartFerguson StuartFerguson merged commit 332de70 into master Feb 23, 2026
10 checks passed
@github-actions github-actions Bot deleted the copilot/update-test-coverage-merchant-statement branch April 25, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Test Coverage on Merchant Statement Domain service

2 participants