Skip to content

Add failure and exception case test coverage for EstateDomainService#1503

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/update-test-coverage-estate-service
Feb 20, 2026
Merged

Add failure and exception case test coverage for EstateDomainService#1503
StuartFerguson merged 3 commits intomasterfrom
copilot/update-test-coverage-estate-service

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 20, 2026

EstateDomainServiceTests only covered happy paths. Each method in EstateDomainService has multiple early-return failure branches (aggregate fetch failure, domain state validation failure, save failure) and a top-level exception handler that were entirely untested.

New failure case tests

CreateEstate

  • GetAggregateOrFailure returns failure
  • estateAggregate.Create() fails (empty estate name)
  • AggregateService.Save() fails

AddOperatorToEstate

  • Get<OperatorAggregate> returns failure
  • GetLatest<EstateAggregate> returns failure
  • estateAggregate.AddOperator() fails (estate not yet created)
  • AggregateService.Save() fails

CreateEstateUser

  • GetLatest<EstateAggregate> returns failure
  • estateAggregate.AddSecurityUser() fails (estate not yet created)
  • AggregateService.Save() fails

RemoveOperatorFromEstate

  • GetLatest<EstateAggregate> returns failure
  • estateAggregate.RemoveOperator() fails (estate not created / operator not added)
  • AggregateService.Save() fails

Each test follows the established pattern — mock the relevant dependency to return Result.Failure() or use an EmptyEstateAggregate to trigger domain validation failure, then assert result.IsFailed.

New exception case tests

Each method also has a catch (Exception ex) block that returns Result.Failure(ex.GetExceptionMessages()). One test per method covers this path by configuring the first dependency call to throw an Exception:

  • EstateDomainService_CreateEstate_ExceptionThrown_ResultIsFailed
  • EstateDomainService_AddOperatorToEstate_ExceptionThrown_ResultIsFailed
  • EstateDomainService_CreateEstateUser_ExceptionThrown_ResultIsFailed
  • EstateDomainService_RemoveOperatorFromEstate_ExceptionThrown_ResultIsFailed
Original prompt

This section details on the original issue you should resolve

<issue_title>Update Test Coverage on Estate Domain service</issue_title>
<issue_description>Each domain service method needs new tests added to cover all failure cases, for example here is the Create Estate method

Image</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Update test coverage for estate domain service methods Add failure case test coverage for EstateDomainService Feb 20, 2026
Copilot AI requested a review from StuartFerguson February 20, 2026 15:02
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot what about the exception cases ?

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

Copilot AI commented Feb 20, 2026

@copilot what about the exception cases ?

Added four exception-case tests in commit a81228e — one per method — each using .ThrowsAsync(new Exception()) on the first dependency to exercise the catch (Exception ex) { return Result.Failure(ex.GetExceptionMessages()); } block in every method.

Copilot AI changed the title Add failure case test coverage for EstateDomainService Add failure and exception case test coverage for EstateDomainService Feb 20, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 20, 2026 15:30
@StuartFerguson StuartFerguson merged commit 690da8a into master Feb 20, 2026
9 of 10 checks passed
@github-actions github-actions Bot deleted the copilot/update-test-coverage-estate-service branch April 22, 2026 02:57
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 Estate Domain service

2 participants