diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/EstateDomainServiceTests.cs index a0d5fb25..8a22100e 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,240 @@ 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(); + } + + [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(); + } } }