From ffeaa08fdb3f88228dff01f0bff45b7fe942b27f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 14:44:48 +0000 Subject: [PATCH 1/3] Initial plan From cae69fc50f5ae11eba76bdfbb6cf7acb8425cf37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:02:11 +0000 Subject: [PATCH 2/3] Add missing failure case tests for EstateDomainService methods Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/EstateDomainServiceTests.cs | 199 +++++++++++++++++- 1 file changed, 196 insertions(+), 3 deletions(-) diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs index a0d5fb25..5644fd89 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs @@ -11,7 +11,9 @@ using Shouldly; using SimpleResults; using TransactionProcessor.Aggregates; +using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.BusinessLogic.Services; +using TransactionProcessor.DataTransferObjects.Requests.Estate; using TransactionProcessor.Testing; using Xunit; @@ -150,8 +152,199 @@ public async Task EstateDomainService_CreateEstateUser_NullUserReturned_ResultIs result.IsFailed.ShouldBeTrue(); } - // TODO: EstateDomainServiceTests - CreateEstateUser - failed creating user test - // TODO: EstateDomainServiceTests - Estate Not Created tests missing - // TODO: EstateDomainServiceTests - Save Changes failed + [Fact] + public async Task EstateDomainService_CreateEstateUser_GetEstateFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + this.SecurityServiceClient + .Setup(s => s.CreateUser(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success); + this.SecurityServiceClient + .Setup(s => s.GetUsers(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(new List() { + new UserDetails { + UserId = Guid.Parse("FA077CE3-B915-4048-88E3-9B500699317F") + } + })); + + Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_CreateEstateUser_EstateNotCreated_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyEstateAggregate)); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success()); + + this.SecurityServiceClient + .Setup(s => s.CreateUser(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success); + this.SecurityServiceClient + .Setup(s => s.GetUsers(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(new List() { + new UserDetails { + UserId = Guid.Parse("FA077CE3-B915-4048-88E3-9B500699317F") + } + })); + + Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_CreateEstateUser_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedEstateAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure); + + this.SecurityServiceClient + .Setup(s => s.CreateUser(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success); + this.SecurityServiceClient + .Setup(s => s.GetUsers(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(new List() { + new UserDetails { + UserId = Guid.Parse("FA077CE3-B915-4048-88E3-9B500699317F") + } + })); + + Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_CreateEstate_GetEstateFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + Result result = await this.DomainService.CreateEstate(TestData.Commands.CreateEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_CreateEstate_EstateNameEmpty_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(new EstateAggregate())); + + EstateCommands.CreateEstateCommand emptyNameCommand = new EstateCommands.CreateEstateCommand( + new CreateEstateRequest { EstateId = TestData.EstateId, EstateName = String.Empty }); + + Result result = await this.DomainService.CreateEstate(emptyNameCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_CreateEstate_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(new EstateAggregate())); + this.AggregateService + .Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure); + + Result result = await this.DomainService.CreateEstate(TestData.Commands.CreateEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_AddOperatorToEstate_GetOperatorFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedEstateAggregate())); + + Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_AddOperatorToEstate_GetEstateFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_AddOperatorToEstate_EstateNotCreated_ResultIsFailed() + { + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.EmptyEstateAggregate)); + + Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_AddOperatorToEstate_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedEstateAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure); + + Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_RemoveOperatorFromEstate_GetEstateFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_RemoveOperatorFromEstate_EstateNotCreated_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyEstateAggregate)); + + Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_RemoveOperatorFromEstate_OperatorNotAdded_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedEstateAggregate())); + + Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_RemoveOperatorFromEstate_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure); + + Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } } } From a81228e731046e9ec9105bf0e5a11fc0aec92805 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:19:08 +0000 Subject: [PATCH 3/3] Add exception case tests for all four EstateDomainService methods Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/EstateDomainServiceTests.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs index 5644fd89..8a22100e 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs @@ -346,5 +346,46 @@ public async Task EstateDomainService_RemoveOperatorFromEstate_SaveFailed_Result Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); } + + [Fact] + public async Task EstateDomainService_CreateEstate_ExceptionThrown_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception()); + + Result result = await this.DomainService.CreateEstate(TestData.Commands.CreateEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_AddOperatorToEstate_ExceptionThrown_ResultIsFailed() + { + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception()); + + Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_CreateEstateUser_ExceptionThrown_ResultIsFailed() + { + this.SecurityServiceClient + .Setup(s => s.CreateUser(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception()); + + Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task EstateDomainService_RemoveOperatorFromEstate_ExceptionThrown_ResultIsFailed() + { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception()); + + Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } } }