From c701d4de3f60c70553e88d435abd2e722d5abe96 Mon Sep 17 00:00:00 2001 From: tom-gough Date: Fri, 2 Nov 2018 10:39:57 +0000 Subject: [PATCH 1/2] removed RelationshipCreationScript --- .../Support/RelationshipCreationScript.sql | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql diff --git a/src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql b/src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql deleted file mode 100644 index aad25a72c3..0000000000 --- a/src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql +++ /dev/null @@ -1,42 +0,0 @@ -/* -Relationship creation script - -The purpose of this script is to create a Employer-Provider Relationship record in commitments. Under normal circumstances, -a Relationship is created when the Employer first sends a Provider a Cohort. When this Relationship is not created due to -technical issues at the time (at time of writing, the two operations are not atomic), when the Provider goes to view the cohort -and exception is thrown and the only known work-around is to have the Employer send another, empty cohort, to their Provider. -*/ - -declare @ProviderId bigint = 0; -- Set the UKPRN of the provider for whom to create the relationship -declare @EmployerAccountId bigint = 0; -- Set the AccountId of the employer for whom to create the relationship -declare @LegalEntityCode nvarchar(50) = ''; --Set the Code of the legal entity for whom to create the relationship - - - -/* -************* MODIFY BELOW THIS LINE AT YOUR PERIL ******************* -*/ - -insert into [dbo].[Relationship] -select -top 1 -c.ProviderId, -c.ProviderName, -c.EmployerAccountId, -c.LegalEntityId, -c.LegalEntityName, -c.LegalEntityAddress, -c.LegalEntityOrganisationType, -null as Verified, -GETDATE() as CreatedOn -from -[dbo].[Commitment] c -where c.ProviderId = @ProviderId and c.EmployerAccountId = @EmployerAccountId and c.LegalEntityId = @LegalEntityCode -and not exists (select 1 from Relationship where ProviderId = @ProviderId and EmployerAccountId = @EmployerAccountId and LegalEntityId = @LegalEntityCode) -order by c.Id desc - - -if(@@ROWCOUNT=0) -begin - print 'Error - Relationship already exists, or no Commitment found' -end From 2d5c2de8cd6e8be8ec513b1eedbd4e0bf83ffe8d Mon Sep 17 00:00:00 2001 From: tom-gough Date: Mon, 5 Nov 2018 10:22:28 +0000 Subject: [PATCH 2/2] Completely removed relationship from commitments api --- src/AzureTopicConfigurationStrucuture.json | 8 - .../Interfaces/IRelationshipApi.cs | 13 -- .../RelationshipApi.cs | 56 ------- .../Relationship.cs | 16 -- .../RelationshipRequest.cs | 8 - .../WhenCreatingACommitment.cs | 3 - .../Controllers/ProviderController.cs | 24 --- .../DependencyResolution/DefaultRegistry.cs | 1 - .../Orchestrators/EmployerOrchestrator.cs | 1 - .../Orchestrators/IProviderOrchestrator.cs | 3 - .../Orchestrators/ProviderOrchestrator.cs | 79 ---------- .../WhenCreatingCommitment.cs | 77 +-------- .../WhenValidatingCommand.cs | 108 ------------- .../WhenVerifyingRelationship.cs | 111 ------------- .../WhenGettingRelationship.cs | 121 -------------- .../GetRelationship/WhenValidatingRequest.cs | 93 ----------- .../WhenGettingRelationshipByCommitment.cs | 147 ------------------ .../WhenValidatingRequest.cs | 76 --------- ...S.Commitments.Application.UnitTests.csproj | 6 - .../CreateCommitmentCommandHandler.cs | 56 +------ .../VerifyRelationshipCommand.cs | 15 -- .../VerifyRelationshipCommandHandler.cs | 45 ------ .../VerifyRelationshipValidator.cs | 16 -- .../GetRelationshipQueryHandler.cs | 40 ----- .../GetRelationship/GetRelationshipRequest.cs | 14 -- .../GetRelationshipResponse.cs | 8 - .../GetRelationshipValidator.cs | 23 --- ...GetRelationshipByCommitmentQueryHandler.cs | 59 ------- .../GetRelationshipByCommitmentRequest.cs | 14 -- .../GetRelationshipByCommitmentResponse.cs | 8 - .../GetRelationshipByCommitmentValidator.cs | 18 --- .../SFA.DAS.Commitments.Application.csproj | 11 -- .../SFA.DAS.Commitments.Database.sqlproj | 5 - .../StoredProcedures/CreateRelationship.sql | 40 ----- .../StoredProcedures/GetRelationship.sql | 23 --- .../StoredProcedures/VerifyRelationship.sql | 14 -- .../Tables/Relationship.sql | 17 -- .../Data/ICommitmentRepository.cs | 2 +- .../Data/IRelationshipRepository.cs | 11 -- .../Entities/Relationship.cs | 15 -- .../SFA.DAS.Commitments.Domain.csproj | 2 - .../RelationshipCreated.cs | 22 --- .../RelationshipVerified.cs | 26 ---- .../SFA.DAS.Commitments.Events.csproj | 2 - .../Data/CommitmentRepository.cs | 12 +- .../Data/RelationshipRepository.cs | 53 ------- .../Transactions/IRelationshipTransactions.cs | 11 -- .../Transactions/RelationshipTransactions.cs | 43 ----- .../SFA.DAS.Commitments.Infrastructure.csproj | 3 - 49 files changed, 16 insertions(+), 1563 deletions(-) delete mode 100644 src/SFA.DAS.Commitments.Api.Client/Interfaces/IRelationshipApi.cs delete mode 100644 src/SFA.DAS.Commitments.Api.Client/RelationshipApi.cs delete mode 100644 src/SFA.DAS.Commitments.Api.Types/Relationship.cs delete mode 100644 src/SFA.DAS.Commitments.Api.Types/RelationshipRequest.cs delete mode 100644 src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenValidatingCommand.cs delete mode 100644 src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenVerifyingRelationship.cs delete mode 100644 src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenGettingRelationship.cs delete mode 100644 src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenValidatingRequest.cs delete mode 100644 src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenGettingRelationshipByCommitment.cs delete mode 100644 src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenValidatingRequest.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommand.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommandHandler.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipValidator.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipQueryHandler.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipRequest.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipResponse.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipValidator.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentQueryHandler.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentRequest.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentResponse.cs delete mode 100644 src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentValidator.cs delete mode 100644 src/SFA.DAS.Commitments.Database/StoredProcedures/CreateRelationship.sql delete mode 100644 src/SFA.DAS.Commitments.Database/StoredProcedures/GetRelationship.sql delete mode 100644 src/SFA.DAS.Commitments.Database/StoredProcedures/VerifyRelationship.sql delete mode 100644 src/SFA.DAS.Commitments.Database/Tables/Relationship.sql delete mode 100644 src/SFA.DAS.Commitments.Domain/Data/IRelationshipRepository.cs delete mode 100644 src/SFA.DAS.Commitments.Domain/Entities/Relationship.cs delete mode 100644 src/SFA.DAS.Commitments.Events/RelationshipCreated.cs delete mode 100644 src/SFA.DAS.Commitments.Events/RelationshipVerified.cs delete mode 100644 src/SFA.DAS.Commitments.Infrastructure/Data/RelationshipRepository.cs delete mode 100644 src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/IRelationshipTransactions.cs delete mode 100644 src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/RelationshipTransactions.cs diff --git a/src/AzureTopicConfigurationStrucuture.json b/src/AzureTopicConfigurationStrucuture.json index fa65b8a94e..5a4caf5fdc 100644 --- a/src/AzureTopicConfigurationStrucuture.json +++ b/src/AzureTopicConfigurationStrucuture.json @@ -46,14 +46,6 @@ { "topicName": "provider_cohort_approval_undone_by_employer", "subscription": [ "Task_ProviderCohortApprovalUndoneByEmployer" ] - }, - { - "topicName": "relationship_created", - "subscription": [ "RDS_RelationshipCreated" ] - }, - { - "topicName": "relationship_verified", - "subscription": [ "RDS_RelationshipVerified" ] } ] diff --git a/src/SFA.DAS.Commitments.Api.Client/Interfaces/IRelationshipApi.cs b/src/SFA.DAS.Commitments.Api.Client/Interfaces/IRelationshipApi.cs deleted file mode 100644 index 95b034fa0a..0000000000 --- a/src/SFA.DAS.Commitments.Api.Client/Interfaces/IRelationshipApi.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Threading.Tasks; - -using SFA.DAS.Commitments.Api.Types; - -namespace SFA.DAS.Commitments.Api.Client.Interfaces -{ - public interface IRelationshipApi - { - Task GetRelationship(long providerId, long employerAccountId, string legalEntityId); - Task GetRelationshipByCommitment(long providerId, long commitmentId); - Task PatchRelationship(long providerId, long employerAccountId, string legalEntityId, RelationshipRequest relationshipRequest); - } -} \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Api.Client/RelationshipApi.cs b/src/SFA.DAS.Commitments.Api.Client/RelationshipApi.cs deleted file mode 100644 index 7ee3b96ea9..0000000000 --- a/src/SFA.DAS.Commitments.Api.Client/RelationshipApi.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; - -using Newtonsoft.Json; - -using SFA.DAS.Commitments.Api.Client.Configuration; -using SFA.DAS.Commitments.Api.Client.Interfaces; -using SFA.DAS.Commitments.Api.Types; -using SFA.DAS.Http; - -namespace SFA.DAS.Commitments.Api.Client -{ - public class RelationshipApi : ApiClientBase, IRelationshipApi - { - private readonly ICommitmentsApiClientConfiguration _configuration; - - public RelationshipApi(HttpClient client, ICommitmentsApiClientConfiguration configuration) - : base(client) - { - if (configuration == null) - throw new ArgumentNullException(nameof(configuration)); - _configuration = configuration; - } - - public async Task GetRelationship(long providerId, long employerAccountId, string legalEntityId) - { - var url = $"{_configuration.BaseUrl}api/provider/{providerId}/relationships/{employerAccountId}/{legalEntityId}"; - return await GetRelationship(url); - } - - public async Task PatchRelationship(long providerId, long employerAccountId, string legalEntityId, RelationshipRequest relationshipRequest) - { - var url = $"{_configuration.BaseUrl}api/provider/{providerId}/relationships/{employerAccountId}/{legalEntityId}"; - await PatchRelationship(url, relationshipRequest); - } - - public async Task GetRelationshipByCommitment(long providerId, long commitmentId) - { - var url = $"{_configuration.BaseUrl}api/provider/{providerId}/relationships/{commitmentId}"; - return await GetRelationship(url); - } - - private async Task GetRelationship(string url) - { - var content = await GetAsync(url); - return JsonConvert.DeserializeObject(content); - } - - private async Task PatchRelationship(string url, RelationshipRequest relationshipRequest) - { - var data = JsonConvert.SerializeObject(relationshipRequest); - await PatchAsync(url, data); - } - } -} \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Api.Types/Relationship.cs b/src/SFA.DAS.Commitments.Api.Types/Relationship.cs deleted file mode 100644 index 6e5129b457..0000000000 --- a/src/SFA.DAS.Commitments.Api.Types/Relationship.cs +++ /dev/null @@ -1,16 +0,0 @@ - -namespace SFA.DAS.Commitments.Api.Types -{ - public class Relationship - { - public long Id { get; set; } - public long EmployerAccountId { get; set; } - public string LegalEntityId { get; set; } - public string LegalEntityName { get; set; } - public string LegalEntityAddress { get; set; } - public SFA.DAS.Common.Domain.Types.OrganisationType LegalEntityOrganisationType { get; set; } - public long ProviderId { get; set; } - public string ProviderName { get; set; } - public bool? Verified { get; set; } - } -} diff --git a/src/SFA.DAS.Commitments.Api.Types/RelationshipRequest.cs b/src/SFA.DAS.Commitments.Api.Types/RelationshipRequest.cs deleted file mode 100644 index a648250555..0000000000 --- a/src/SFA.DAS.Commitments.Api.Types/RelationshipRequest.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SFA.DAS.Commitments.Api.Types -{ - public class RelationshipRequest - { - public Relationship Relationship { get; set; } - public string UserId { get; set; } - } -} diff --git a/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenCreatingACommitment.cs b/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenCreatingACommitment.cs index 2e9a0fa97a..b0c5691c16 100644 --- a/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenCreatingACommitment.cs +++ b/src/SFA.DAS.Commitments.Api.UnitTests/Controllers/EmployerControllerTests/WhenCreatingACommitment.cs @@ -12,7 +12,6 @@ using SFA.DAS.Commitments.Api.Orchestrators.Mappers; using SFA.DAS.Commitments.Api.Types.Commitment; using SFA.DAS.Commitments.Application.Commands.CreateCommitment; -using SFA.DAS.Commitments.Application.Queries.GetRelationship; using SFA.DAS.Commitments.Domain.Interfaces; using SFA.DAS.HashingService; using Commitment = SFA.DAS.Commitments.Api.Types.Commitment.Commitment; @@ -39,8 +38,6 @@ public void Setup() _mappedCommitment = new Fixture().Create(); _commitmentMapper.Setup(m => m.MapFrom(It.IsAny())) .Returns(_mappedCommitment); - _mockMediator.Setup(m => m.SendAsync(It.IsAny())) - .ReturnsAsync(new GetRelationshipResponse()); _employerOrchestrator = new EmployerOrchestrator( _mockMediator.Object, diff --git a/src/SFA.DAS.Commitments.Api/Controllers/ProviderController.cs b/src/SFA.DAS.Commitments.Api/Controllers/ProviderController.cs index 81dc87306a..7c72d152da 100644 --- a/src/SFA.DAS.Commitments.Api/Controllers/ProviderController.cs +++ b/src/SFA.DAS.Commitments.Api/Controllers/ProviderController.cs @@ -181,30 +181,6 @@ public async Task DeleteApprenticeship(long providerId, long return StatusCode(HttpStatusCode.NoContent); } - [Route("{providerId}/relationships/{employerAccountId}/{legalEntityId}")] - [AuthorizeRemoteOnly(Roles = "Role1")] - public async Task GetRelationshipByProviderAndLegalEntityId(long providerId, long employerAccountId, string legalEntityId) - { - var response = await _providerOrchestrator.GetRelationship(providerId, employerAccountId, legalEntityId); - return Ok(response); - } - - [Route("{providerId}/relationships/{commitmentId}")] - [AuthorizeRemoteOnly(Roles = "Role1")] - public async Task GetRelationshipByCommitment(long providerId, long commitmentId) - { - var response = await _providerOrchestrator.GetRelationship(providerId, commitmentId); - return Ok(response); - } - - [Route("{providerId}/relationships/{employerAccountId}/{legalEntityId}")] - [AuthorizeRemoteOnly(Roles = "Role1")] - public async Task PatchRelationship(long providerId, long employerAccountId, string legalEntityId, [FromBody] RelationshipRequest request) - { - await _providerOrchestrator.PatchRelationship(providerId, employerAccountId, legalEntityId, request); - return StatusCode(HttpStatusCode.NoContent); - } - [Route("{providerId}/apprenticeships/{apprenticeshipId}/update")] [AuthorizeRemoteOnly(Roles = "Role1")] public async Task GetPendingApprenticeshipUpdate(long providerId, long apprenticeshipId) diff --git a/src/SFA.DAS.Commitments.Api/DependencyResolution/DefaultRegistry.cs b/src/SFA.DAS.Commitments.Api/DependencyResolution/DefaultRegistry.cs index 20fe0c05e7..a222ddfb71 100644 --- a/src/SFA.DAS.Commitments.Api/DependencyResolution/DefaultRegistry.cs +++ b/src/SFA.DAS.Commitments.Api/DependencyResolution/DefaultRegistry.cs @@ -76,7 +76,6 @@ public DefaultRegistry() For().Use().Ctor().Is(config.DatabaseConnectionString); For().Use().Ctor().Is(config.DatabaseConnectionString); For().Use().Ctor().Is(config.DatabaseConnectionString); - For().Use().Ctor().Is(config.DatabaseConnectionString); For().Use(ctx => t => ctx.GetInstance(t)); For().Use(ctx => t => ctx.GetAllInstances(t)); diff --git a/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs b/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs index 3de920f868..2baf95ef4e 100644 --- a/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs +++ b/src/SFA.DAS.Commitments.Api/Orchestrators/EmployerOrchestrator.cs @@ -44,7 +44,6 @@ using Originator = SFA.DAS.Commitments.Api.Types.Apprenticeship.Types.Originator; using PaymentStatus = SFA.DAS.Commitments.Api.Types.Apprenticeship.Types.PaymentStatus; using ProviderPaymentPriorityItem = SFA.DAS.Commitments.Api.Types.ProviderPayment.ProviderPaymentPriorityItem; -using Relationship = SFA.DAS.Commitments.Domain.Entities.Relationship; using TransferApprovalStatus = SFA.DAS.Commitments.Api.Types.TransferApprovalStatus; namespace SFA.DAS.Commitments.Api.Orchestrators diff --git a/src/SFA.DAS.Commitments.Api/Orchestrators/IProviderOrchestrator.cs b/src/SFA.DAS.Commitments.Api/Orchestrators/IProviderOrchestrator.cs index bf3a680ef7..c6a9ff5fe5 100644 --- a/src/SFA.DAS.Commitments.Api/Orchestrators/IProviderOrchestrator.cs +++ b/src/SFA.DAS.Commitments.Api/Orchestrators/IProviderOrchestrator.cs @@ -21,9 +21,6 @@ public interface IProviderOrchestrator Task ApproveCohort(long providerId, long commitmentId, CommitmentSubmission submission); Task DeleteApprenticeship(long providerId, long apprenticeshipId, string userId, string userName); Task DeleteCommitment(long providerId, long commitmentId, string userId, string userName); - Task GetRelationship(long providerId, long employerAccountId, string legalEntityId); - Task GetRelationship(long providerId, long commitmentId); - Task PatchRelationship(long providerId, long employerAccountId, string legalEntityId, RelationshipRequest patchRequest); Task GetPendingApprenticeshipUpdate(long providerId, long apprenticeshipId); Task CreateApprenticeshipUpdate(long providerId, ApprenticeshipUpdateRequest updateRequest); Task PatchApprenticeshipUpdate(long providerId, long apprenticeshipId, ApprenticeshipUpdateSubmission submission); diff --git a/src/SFA.DAS.Commitments.Api/Orchestrators/ProviderOrchestrator.cs b/src/SFA.DAS.Commitments.Api/Orchestrators/ProviderOrchestrator.cs index ea1e75b646..58f107acf2 100644 --- a/src/SFA.DAS.Commitments.Api/Orchestrators/ProviderOrchestrator.cs +++ b/src/SFA.DAS.Commitments.Api/Orchestrators/ProviderOrchestrator.cs @@ -14,15 +14,12 @@ using SFA.DAS.Commitments.Application.Commands.DeleteCommitment; using SFA.DAS.Commitments.Application.Commands.UpdateApprenticeship; using SFA.DAS.Commitments.Application.Commands.UpdateCommitmentAgreement; -using SFA.DAS.Commitments.Application.Commands.VerifyRelationship; using SFA.DAS.Commitments.Application.Queries.GetApprenticeship; using SFA.DAS.Commitments.Application.Queries.GetApprenticeships; using SFA.DAS.Commitments.Application.Queries.GetBulkUploadFile; using SFA.DAS.Commitments.Application.Queries.GetCommitment; using SFA.DAS.Commitments.Application.Queries.GetCommitments; using SFA.DAS.Commitments.Application.Queries.GetPendingApprenticeshipUpdate; -using SFA.DAS.Commitments.Application.Queries.GetRelationship; -using SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment; using SFA.DAS.Commitments.Domain; using SFA.DAS.Commitments.Domain.Interfaces; @@ -39,7 +36,6 @@ using SFA.DAS.Commitments.Domain.Entities; using Apprenticeship = SFA.DAS.Commitments.Api.Types.Apprenticeship.Apprenticeship; -using Relationship = SFA.DAS.Commitments.Domain.Entities.Relationship; namespace SFA.DAS.Commitments.Api.Orchestrators { @@ -351,65 +347,6 @@ await _mediator.SendAsync(new DeleteCommitmentCommand _logger.Info($"Deleted commitment {commitmentId} for provider {providerId}", providerId: providerId, commitmentId: commitmentId); } - public async Task GetRelationship(long providerId, long employerAccountId, string legalEntityId) - { - _logger.Trace($"Getting relationship for provider {providerId}, employer {employerAccountId}, legal entity {legalEntityId}", employerAccountId, providerId); - - var response = await _mediator.SendAsync(new GetRelationshipRequest - { - Caller = new Caller(providerId, CallerType.Provider), - ProviderId = providerId, - EmployerAccountId = employerAccountId, - LegalEntityId = legalEntityId - }); - - if (response.Data == null) - { - _logger.Info($"Relationship not found for provider {providerId}, employer {employerAccountId}, legal entity {legalEntityId}", employerAccountId, providerId); - return null; - } - - _logger.Info($"Retrieved relationship for provider {providerId}, employer {employerAccountId}, legal entity {legalEntityId}", employerAccountId, providerId); - - return Map(response.Data); - } - - public async Task GetRelationship(long providerId, long commitmentId) - { - _logger.Trace($"Getting relationship for provider {providerId}, commitment {commitmentId}", null, providerId, commitmentId); - - var response = await _mediator.SendAsync(new GetRelationshipByCommitmentRequest - { - Caller = new Caller(providerId, CallerType.Provider), - ProviderId = providerId, - CommitmentId = commitmentId - }); - - if (response.Data != null) - _logger.Info($"Getting relationship for provider {providerId}, commitment {commitmentId}", null, providerId, commitmentId); - else - _logger.Info($"Relationship not found for provider {providerId}, commitment {commitmentId}", null, providerId, commitmentId); - - return Map(response.Data); - } - - public async Task PatchRelationship(long providerId, long employerAccountId, string legalEntityId, RelationshipRequest patchRequest) - { - _logger.Trace($"Verifying relationship for provider {providerId}, employer {employerAccountId}, legal entity {legalEntityId}", employerAccountId, providerId); - - await _mediator.SendAsync(new VerifyRelationshipCommand - { - Caller = new Caller(providerId, CallerType.Provider), - ProviderId = providerId, - EmployerAccountId = employerAccountId, - LegalEntityId = legalEntityId, - UserId = patchRequest.UserId, - Verified = patchRequest.Relationship.Verified - }); - - _logger.Info($"Verified relationship for provider {providerId}, employer {employerAccountId}, legal entity {legalEntityId}", employerAccountId, providerId); - } - public async Task GetPendingApprenticeshipUpdate(long providerId, long apprenticeshipId) { _logger.Trace($"Getting pending update for apprenticeship {apprenticeshipId} for provider account {providerId}", providerId: providerId, apprenticeshipId: apprenticeshipId); @@ -516,21 +453,5 @@ public async Task GetBulkUploadFile(long providerId, long bulkUploadFile _logger.Info($"Retrieved bulk upload for provider {providerId}", providerId: providerId); return result.Data; } - - private Types.Relationship Map(Relationship entity) - { - return new Types.Relationship - { - EmployerAccountId = entity.EmployerAccountId, - Id = entity.Id, - LegalEntityId = entity.LegalEntityId, - LegalEntityName = entity.LegalEntityName, - LegalEntityAddress = entity.LegalEntityAddress, - LegalEntityOrganisationType = entity.LegalEntityOrganisationType, - ProviderId = entity.ProviderId, - ProviderName = entity.ProviderName, - Verified = entity.Verified - }; - } } } \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/CreateCommitment/WhenCreatingCommitment.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/CreateCommitment/WhenCreatingCommitment.cs index d570617ce0..5783f7ac0f 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/CreateCommitment/WhenCreatingCommitment.cs +++ b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/CreateCommitment/WhenCreatingCommitment.cs @@ -26,7 +26,6 @@ namespace SFA.DAS.Commitments.Application.UnitTests.Commands.CreateCommitment public sealed class WhenCreatingCommitment { private Mock _mockCommitmentRespository; - private Mock _mockRelationshipRepository; private CreateCommitmentCommandHandler _handler; private CreateCommitmentCommand _exampleValidRequest; private Mock _mockHashingService; @@ -39,22 +38,17 @@ public sealed class WhenCreatingCommitment public void SetUp() { _mockCommitmentRespository = new Mock(); - _mockRelationshipRepository = new Mock(); _mockHashingService = new Mock(); var commandValidator = new CreateCommitmentValidator(); _mockHistoryRepository = new Mock(); _messagePublisher = new Mock(); - _mockRelationshipRepository.Setup(x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(new Relationship()); - _handler = new CreateCommitmentCommandHandler(_mockCommitmentRespository.Object, _mockHashingService.Object, commandValidator, Mock.Of(), _mockHistoryRepository.Object, - _messagePublisher.Object, - _mockRelationshipRepository.Object); + _messagePublisher.Object); var fixture = new Fixture(); fixture.Customize(ob => ob @@ -86,7 +80,7 @@ public async Task ThenShouldCallTheRepository() { await _handler.Handle(_exampleValidRequest); - _mockCommitmentRespository.Verify(x => x.Create(It.IsAny(), It.IsAny())); + _mockCommitmentRespository.Verify(x => x.Create(It.IsAny())); } [Test] @@ -95,9 +89,9 @@ public async Task ThenShouldCallTheRepositoryWithCommitmentMappedFromRequest() //Arrange Commitment argument = null; _mockCommitmentRespository.Setup( - x => x.Create(It.IsAny(), It.IsAny())) + x => x.Create(It.IsAny())) .ReturnsAsync(4) - .Callback((commitment, relationship) => argument = commitment); + .Callback((commitment) => argument = commitment); //Act await _handler.Handle(TestHelper.Clone(_exampleValidRequest)); @@ -111,7 +105,7 @@ public async Task ThenShouldCallTheRepositoryWithCommitmentMappedFromRequest() public async Task ThenShouldReturnTheCommitmentIdReturnedFromRepository() { const long expectedCommitmentId = 45; - _mockCommitmentRespository.Setup(x => x.Create(It.IsAny(), It.IsAny())).ReturnsAsync(expectedCommitmentId); + _mockCommitmentRespository.Setup(x => x.Create(It.IsAny())).ReturnsAsync(expectedCommitmentId); var commitmentId = await _handler.Handle(_exampleValidRequest); @@ -145,7 +139,7 @@ public async Task ThenIfAMessageIsProvidedThenTheMessageIsSaved() { //Arange const long expectedCommitmentId = 45; - _mockCommitmentRespository.Setup(x => x.Create(It.IsAny(), It.IsAny())).ReturnsAsync(expectedCommitmentId); + _mockCommitmentRespository.Setup(x => x.Create(It.IsAny())).ReturnsAsync(expectedCommitmentId); _exampleValidRequest.Message = "New Message"; //Act @@ -164,7 +158,7 @@ public async Task ThenIfAMessageIsProvidedThenTheMessageIsSaved() public async Task ThenAHistoryRecordIsCreated() { const long expectedCommitmentId = 45; - _mockCommitmentRespository.Setup(x => x.Create(It.IsAny(), It.IsAny())).ReturnsAsync(expectedCommitmentId); + _mockCommitmentRespository.Setup(x => x.Create(It.IsAny())).ReturnsAsync(expectedCommitmentId); await _handler.Handle(_exampleValidRequest); @@ -189,7 +183,7 @@ public async Task ThenAHistoryRecordIsCreated() public async Task ThenTheCohortEventIsCreated() { const long expectedCommitmentId = 45; - _mockCommitmentRespository.Setup(x => x.Create(It.IsAny(), It.IsAny())).ReturnsAsync(expectedCommitmentId); + _mockCommitmentRespository.Setup(x => x.Create(It.IsAny())).ReturnsAsync(expectedCommitmentId); await _handler.Handle(_exampleValidRequest); @@ -200,61 +194,6 @@ public async Task ThenTheCohortEventIsCreated() m => m.AccountId == _exampleValidRequest.Commitment.EmployerAccountId && m.ProviderId == _exampleValidRequest.Commitment.ProviderId.Value && m.CommitmentId == expectedCommitmentId)), Times.Once); } - [Test] - public async Task ThenIfRelationshipDoesNotExistThenItIsCreated() - { - //Arrange - _mockRelationshipRepository.Setup(x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(null as Relationship); - - //Act - await _handler.Handle(TestHelper.Clone(_exampleValidRequest)); - - //Assert - _mockCommitmentRespository.Verify(x => x.Create(It.IsAny(), It.Is(r => - r.EmployerAccountId == _exampleValidRequest.Commitment.EmployerAccountId - && r.LegalEntityId == _exampleValidRequest.Commitment.LegalEntityId - && r.ProviderId == _exampleValidRequest.Commitment.ProviderId)), Times.Once); - } - - [Test] - public async Task ThenIfRelationshipExistsThenAnotherIsNotCreated() - { - //Act - await _handler.Handle(TestHelper.Clone(_exampleValidRequest)); - - //Assert - _mockCommitmentRespository.Verify(x => x.Create(It.IsAny(), It.Is(r => r == null)), Times.Once); - } - - [Test] - public async Task ThenIfRelationshipIsCreatedThenRelationshipCreatedEventIsEmitted() - { - //Arrange - _mockRelationshipRepository.Setup(x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(null as Relationship); - - //Act - await _handler.Handle(TestHelper.Clone(_exampleValidRequest)); - - //Assert - _messagePublisher.Verify(x => x.PublishAsync(It.Is(e => - e.Relationship.EmployerAccountId == _exampleValidRequest.Commitment.EmployerAccountId && - e.Relationship.LegalEntityId == _exampleValidRequest.Commitment.LegalEntityId && - e.Relationship.ProviderId == _exampleValidRequest.Commitment.ProviderId)), - Times.Once); - } - - [Test] - public async Task ThenIfRelationshipIsNotCreatedThenRelationshipCreatedEventIsNotEmitted() - { - //Act - await _handler.Handle(TestHelper.Clone(_exampleValidRequest)); - - //Assert - _messagePublisher.Verify(x => x.PublishAsync(It.IsAny()), Times.Never); - } - private void AssertMappingIsCorrect(Commitment argument) { argument.Reference.Should().Be(_exampleValidRequest.Commitment.Reference); diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenValidatingCommand.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenValidatingCommand.cs deleted file mode 100644 index 8f428eba16..0000000000 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenValidatingCommand.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System.Linq; -using NUnit.Framework; -using SFA.DAS.Commitments.Application.Commands.VerifyRelationship; - -namespace SFA.DAS.Commitments.Application.UnitTests.Commands.VerifyRelationship -{ - [TestFixture] - public class WhenValidatingCommand - { - private VerifyRelationshipValidator _validator; - - [SetUp] - public void Setup() - { - _validator = new VerifyRelationshipValidator(); - } - - [Test] - public void ThenRequestIsValidIfAllFieldsAreProvided() - { - //Arrange - var request = new VerifyRelationshipCommand - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3", - UserId = "User", - Verified = true - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsTrue(result.IsValid); - } - - [Test] - public void ThenEmployerAccountIdIsMandatory() - { - //Arrange - var request = new VerifyRelationshipCommand(); - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(e=> e.PropertyName=="EmployerAccountId")); - } - - [Test] - public void ThenLegalEntityIdIsMandatory() - { - //Arrange - var request = new VerifyRelationshipCommand(); - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(e => e.PropertyName == "LegalEntityId")); - } - - [Test] - public void ThenProviderIdIsMandatory() - { - //Arrange - var request = new VerifyRelationshipCommand(); - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(e => e.PropertyName == "ProviderId")); - } - - [Test] - public void ThenUserIdIsMandatory() - { - //Arrange - var request = new VerifyRelationshipCommand(); - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(e => e.PropertyName == "UserId")); - } - - [Test] - public void ThenVerifiedIsMandatory() - { - //Arrange - var request = new VerifyRelationshipCommand(); - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(e => e.PropertyName == "Verified")); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenVerifyingRelationship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenVerifyingRelationship.cs deleted file mode 100644 index a05ec8efe4..0000000000 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Commands/VerifyRelationship/WhenVerifyingRelationship.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System.Threading.Tasks; -using FluentValidation; -using FluentValidation.Results; -using MediatR; -using Moq; -using NUnit.Framework; -using SFA.DAS.Commitments.Application.Commands.VerifyRelationship; -using SFA.DAS.Commitments.Domain.Data; -using SFA.DAS.Commitments.Domain.Interfaces; -using SFA.DAS.Commitments.Events; -using SFA.DAS.Messaging.Interfaces; - -namespace SFA.DAS.Commitments.Application.UnitTests.Commands.VerifyRelationship -{ - [TestFixture] - public class WhenVerifyingRelationship - { - private VerifyRelationshipCommandHandler _handler; - - private Mock _validator; - private Mock _relationshipRepository; - private Mock _messagePublisher; - - [SetUp] - public void Arrange() - { - _validator = new Mock(); - - _relationshipRepository = new Mock(); - _messagePublisher = new Mock(); - _relationshipRepository.Setup(x => x.VerifyRelationship(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(()=> Task.FromResult(new Unit())); - - _handler = new VerifyRelationshipCommandHandler(_relationshipRepository.Object, _validator.Object, Mock.Of(), _messagePublisher.Object); - } - - [Test] - public async Task ThenIfTheRequestIsValidThenTheRepositoryIsCalled() - { - //Arrange - var request = new VerifyRelationshipCommand - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3", - Verified = true - }; - _validator.Setup(x => x.Validate(It.IsAny())).Returns(new ValidationResult()); - - - //Act - await _handler.Handle(request); - - //Assert - _relationshipRepository.Verify(x => x.VerifyRelationship( - It.Is(y=> y == 1), - It.Is(y => y == 2), - It.Is(y => y == "L3"), - It.Is(y => y == true)), - Times.Once); - } - - [Test] - public void ThenIfTheRequestIsNotValidThenTheRepositoryIsNotCalled() - { - //Arrange - var request = new VerifyRelationshipCommand(); - _validator.Setup(x => x.Validate(It.IsAny())) - .Returns(new ValidationResult - { - Errors = { new ValidationFailure("Test", "Test Error") } - }); - - //Act & Assert - Assert.ThrowsAsync(() => - _handler.Handle(request) - ); - - _relationshipRepository.Verify(x => x.VerifyRelationship( - It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny()), - Times.Never); - } - - [Test] - public async Task ThenTheRelationshipEventIsCreated() - { - // Arrange - var request = new VerifyRelationshipCommand - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "3", - Verified = true - }; - - _validator.Setup(x => x.Validate(It.IsAny())).Returns(new ValidationResult()); - - // Act - await _handler.Handle(request); - - // Assert - _messagePublisher.Verify(x => - x.PublishAsync(It.Is(y => y.EmployerAccountId == request.EmployerAccountId && - y.ProviderId == request.ProviderId && - y.LegalEntityId == request.LegalEntityId)), Times.Once); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenGettingRelationship.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenGettingRelationship.cs deleted file mode 100644 index 5ede70ca0c..0000000000 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenGettingRelationship.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System.Threading.Tasks; -using FluentValidation; -using FluentValidation.Results; -using Moq; -using NUnit.Framework; -using SFA.DAS.Commitments.Application.Queries.GetRelationship; -using SFA.DAS.Commitments.Domain.Data; -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Application.UnitTests.Queries.GetRelationship -{ - [TestFixture] - public class WhenGettingRelationship - { - private Mock _mockRelationshipRepository; - private Mock> _validator; - private Relationship _repositoryRecord; - private GetRelationshipQueryHandler _handler; - - [SetUp] - public void Arrange() - { - _mockRelationshipRepository = new Mock(); - - _repositoryRecord = new Relationship - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3", - ProviderName = "Test Provider", - Id = 101, - LegalEntityName = "Test Legal Entity", - Verified = false - }; - - _mockRelationshipRepository.Setup( - x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(_repositoryRecord); - - _validator = new Mock>(); - _validator.Setup(x => x.Validate(It.IsAny())).Returns(() => new ValidationResult()); - - _handler = new GetRelationshipQueryHandler(_mockRelationshipRepository.Object, _validator.Object); - } - - [Test] - public async Task ThenTheRepositoryIsCalledToGetRelationship() - { - //Act - await _handler.Handle(new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3" - }); - - //Assert - _mockRelationshipRepository.Verify(x=> x.GetRelationship( - It.Is(accountId => accountId == 1), - It.Is(providerId => providerId == 2), - It.Is(legalEntityId => legalEntityId == "L3"))); - } - - [Test] - public async Task ThenValidationIsPerformed() - { - //Act - await _handler.Handle(new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3" - }); - - //Assert - _validator.Verify(x=> x.Validate(It.IsAny())); - } - - - [Test] - public async Task ThenTheEntityIsMappedToTheModel() - { - //Act - var result = await _handler.Handle(new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3" - }); - - //Assert - Assert.AreEqual(_repositoryRecord.LegalEntityId, result.Data.LegalEntityId); - Assert.AreEqual(_repositoryRecord.EmployerAccountId, result.Data.EmployerAccountId); - Assert.AreEqual(_repositoryRecord.LegalEntityName, result.Data.LegalEntityName); - Assert.AreEqual(_repositoryRecord.ProviderName, result.Data.ProviderName); - Assert.AreEqual(_repositoryRecord.Verified, result.Data.Verified); - Assert.AreEqual(_repositoryRecord.Id, result.Data.Id); - Assert.AreEqual(_repositoryRecord.ProviderId, result.Data.ProviderId); - } - - [Test] - public async Task ThenIfTheRelationshipIsNotFoundThenTheModelWillBeNull() - { - //Arrange - _mockRelationshipRepository.Setup( - x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync((Relationship)null); - - //Act - var result = await _handler.Handle(new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3" - }); - - //Assert - Assert.IsNull(result.Data); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenValidatingRequest.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenValidatingRequest.cs deleted file mode 100644 index 22da2d7fce..0000000000 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationship/WhenValidatingRequest.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Linq; -using NUnit.Framework; -using SFA.DAS.Commitments.Application.Queries.GetRelationship; - -namespace SFA.DAS.Commitments.Application.UnitTests.Queries.GetRelationship -{ - [TestFixture] - public class WhenValidatingRequest - { - private GetRelationshipValidator _validator; - - [SetUp] - public void Arrange() - { - _validator = new GetRelationshipValidator(); - } - - [Test] - public void ThenRequestIsValidIfAllPropertiesAreProvided() - { - // Arrange - var request = new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "L3" - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsTrue(result.IsValid); - } - - [Test] - public void ThenEmployerAccountIdIsMandatory() - { - //Arrange - var request = new GetRelationshipRequest - { - EmployerAccountId = 0, - ProviderId = 2, - LegalEntityId = "L3" - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(x=> x.PropertyName =="EmployerAccountId")); - } - - [Test] - public void ThenProviderIdisMandatory() - { - //Arrange - var request = new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 0, - LegalEntityId = "L3" - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(x => x.PropertyName == "ProviderId")); - } - - [Test] - public void ThenLegalEntityIsMandatory() - { - //Arrange - var request = new GetRelationshipRequest - { - EmployerAccountId = 1, - ProviderId = 2, - LegalEntityId = "" - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(x => x.PropertyName == "LegalEntityId")); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenGettingRelationshipByCommitment.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenGettingRelationshipByCommitment.cs deleted file mode 100644 index af10767444..0000000000 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenGettingRelationshipByCommitment.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System.Threading.Tasks; -using FluentValidation; -using FluentValidation.Results; -using Moq; -using NUnit.Framework; -using SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment; -using SFA.DAS.Commitments.Domain; -using SFA.DAS.Commitments.Domain.Data; -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Application.UnitTests.Queries.GetRelationshipByCommitment -{ - [TestFixture] - public class WhenGettingRelationshipByCommitment - { - private Mock _mockCommitmentRespository; - private Mock _mockRelationshipRepository; - private Mock> _validator; - private Relationship _repositoryRecord; - private Commitment _commitmentRecord; - private GetRelationshipByCommitmentQueryHandler _handler; - - [SetUp] - public void Arrange() - { - _mockCommitmentRespository = new Mock(); - _mockRelationshipRepository = new Mock(); - - _repositoryRecord = new Relationship - { - Id = 101, - EmployerAccountId = 1, - ProviderId = 1, - LegalEntityId = "L3", - LegalEntityName = "Test Legal Entity", - ProviderName = "Test Provider Name", - Verified = true - }; - - _commitmentRecord = new Commitment - { - Id = 1, - EmployerAccountId = 1, - ProviderId = 1, - LegalEntityId = "L3", - }; - - _mockRelationshipRepository.Setup( - x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(_repositoryRecord); - - _mockCommitmentRespository.Setup( - x => x.GetCommitmentById(It.IsAny())) - .ReturnsAsync(_commitmentRecord); - - _validator = new Mock>(); - _validator.Setup(x => x.Validate(It.IsAny())).Returns(() => new ValidationResult()); - - _handler = new GetRelationshipByCommitmentQueryHandler(_mockCommitmentRespository.Object, _validator.Object, _mockRelationshipRepository.Object); - } - - [Test] - public async Task ThenTheRepositoryIsCalledToGetRelationship() - { - //Act - await _handler.Handle(new GetRelationshipByCommitmentRequest - { - Caller = new Caller(1, CallerType.Provider), - CommitmentId = 2 - }); - - //Assert - _mockRelationshipRepository.Verify(x => x.GetRelationship( - It.Is(accountId => accountId == 1), - It.Is(providerId => providerId == 1), - It.Is(legalEntityId => legalEntityId == "L3")), Times.Once); - } - - [Test] - public async Task ThenTheRepositoryIsCalledToGetCommitment() - { - //Act - await _handler.Handle(new GetRelationshipByCommitmentRequest - { - Caller = new Caller(1, CallerType.Provider), - CommitmentId = 2 - }); - - //Assert - _mockCommitmentRespository.Verify(x => x.GetCommitmentById(It.IsAny()), Times.Once); - } - - [Test] - public async Task ThenValidationIsPerformed() - { - //Act - await _handler.Handle(new GetRelationshipByCommitmentRequest - { - Caller = new Caller(1, CallerType.Provider), - CommitmentId = 2 - }); - - //Assert - _validator.Verify(x => x.Validate(It.IsAny()), Times.Once); - } - - - [Test] - public async Task ThenTheEntityIsMappedToTheModel() - { - //Act - var result = await _handler.Handle(new GetRelationshipByCommitmentRequest - { - Caller = new Caller(1, CallerType.Provider), - CommitmentId = 2 - }); - - //Assert - Assert.AreEqual(_repositoryRecord.LegalEntityId, result.Data.LegalEntityId); - Assert.AreEqual(_repositoryRecord.EmployerAccountId, result.Data.EmployerAccountId); - Assert.AreEqual(_repositoryRecord.LegalEntityName, result.Data.LegalEntityName); - Assert.AreEqual(_repositoryRecord.ProviderName, result.Data.ProviderName); - Assert.AreEqual(_repositoryRecord.Verified, result.Data.Verified); - Assert.AreEqual(_repositoryRecord.Id, result.Data.Id); - Assert.AreEqual(_repositoryRecord.ProviderId, result.Data.ProviderId); - } - - [Test] - public async Task ThenIfTheRelationshipIsNotFoundThenTheModelWillBeNull() - { - //Arrange - _mockRelationshipRepository.Setup( - x => x.GetRelationship(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync((Relationship)null); - - //Act - var result = await _handler.Handle(new GetRelationshipByCommitmentRequest - { - Caller = new Caller(1, CallerType.Provider), - CommitmentId = 2 - }); - - //Assert - Assert.IsNull(result.Data); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenValidatingRequest.cs b/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenValidatingRequest.cs deleted file mode 100644 index 83ece5a844..0000000000 --- a/src/SFA.DAS.Commitments.Application.UnitTests/Queries/GetRelationshipByCommitment/WhenValidatingRequest.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NUnit.Framework; -using SFA.DAS.Commitments.Application.Queries.GetRelationship; -using SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment; - -namespace SFA.DAS.Commitments.Application.UnitTests.Queries.GetRelationshipByCommitment -{ - [TestFixture] - public class WhenValidatingRequest - { - private GetRelationshipByCommitmentValidator _validator; - - [SetUp] - public void Arrange() - { - _validator = new GetRelationshipByCommitmentValidator(); - } - - [Test] - public void ThenRequestIsValidIfAllPropertiesAreProvided() - { - // Arrange - var request = new GetRelationshipByCommitmentRequest - { - ProviderId = 1, - CommitmentId = 2 - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsTrue(result.IsValid); - } - - [Test] - public void ThenProviderIdIsMandatory() - { - //Arrange - var request = new GetRelationshipByCommitmentRequest - { - ProviderId = 0, - CommitmentId = 2 - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(x => x.PropertyName == "ProviderId")); - } - - [Test] - public void ThenCommitmentIdIsMandatory() - { - //Arrange - var request = new GetRelationshipByCommitmentRequest - { - ProviderId = 1, - CommitmentId = 0 - }; - - //Act - var result = _validator.Validate(request); - - //Assert - Assert.IsFalse(result.IsValid); - Assert.IsTrue(result.Errors.Any(x => x.PropertyName == "CommitmentId")); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application.UnitTests/SFA.DAS.Commitments.Application.UnitTests.csproj b/src/SFA.DAS.Commitments.Application.UnitTests/SFA.DAS.Commitments.Application.UnitTests.csproj index bbf7114514..76810eef1e 100644 --- a/src/SFA.DAS.Commitments.Application.UnitTests/SFA.DAS.Commitments.Application.UnitTests.csproj +++ b/src/SFA.DAS.Commitments.Application.UnitTests/SFA.DAS.Commitments.Application.UnitTests.csproj @@ -202,8 +202,6 @@ - - @@ -239,10 +237,6 @@ - - - - diff --git a/src/SFA.DAS.Commitments.Application/Commands/CreateCommitment/CreateCommitmentCommandHandler.cs b/src/SFA.DAS.Commitments.Application/Commands/CreateCommitment/CreateCommitmentCommandHandler.cs index ceedf40305..f0d29556a5 100644 --- a/src/SFA.DAS.Commitments.Application/Commands/CreateCommitment/CreateCommitmentCommandHandler.cs +++ b/src/SFA.DAS.Commitments.Application/Commands/CreateCommitment/CreateCommitmentCommandHandler.cs @@ -20,7 +20,6 @@ public sealed class CreateCommitmentCommandHandler : IAsyncRequestHandler _validator; private readonly ICommitmentRepository _commitmentRepository; - private readonly IRelationshipRepository _relationshipRepository; private readonly IHashingService _hashingService; private readonly ICommitmentsLogger _logger; private readonly IHistoryRepository _historyRepository; @@ -31,8 +30,7 @@ public CreateCommitmentCommandHandler(ICommitmentRepository commitmentRepository AbstractValidator validator, ICommitmentsLogger logger, IHistoryRepository historyRepository, - IMessagePublisher messagePublisher, - IRelationshipRepository relationshipRepository) + IMessagePublisher messagePublisher) { _commitmentRepository = commitmentRepository; _hashingService = hashingService; @@ -40,7 +38,6 @@ public CreateCommitmentCommandHandler(ICommitmentRepository commitmentRepository _logger = logger; _historyRepository = historyRepository; _messagePublisher = messagePublisher; - _relationshipRepository = relationshipRepository; } public async Task Handle(CreateCommitmentCommand message) @@ -54,19 +51,12 @@ public async Task Handle(CreateCommitmentCommand message) throw new ValidationException(validationResult.Errors); } - Relationship relationship = null; - if (await _relationshipRepository.GetRelationship(message.Commitment.EmployerAccountId, message.Commitment.ProviderId.Value, message.Commitment.LegalEntityId) == null) - { - relationship = CreateRelationshipFromCommitment(message.Commitment); - } - - var newCommitment = await CreateCommitment(message, relationship); + var newCommitment = await CreateCommitment(message); await Task.WhenAll( CreateMessageIfNeeded(newCommitment.Id, message), CreateHistory(newCommitment, message.Caller.CallerType, message.UserId, message.Commitment.LastUpdatedByEmployerName), - PublishCohortCreatedEvent(newCommitment), - PublishRelationshipCreatedEventIfNeeded(relationship) + PublishCohortCreatedEvent(newCommitment) ); return newCommitment.Id; @@ -78,12 +68,12 @@ await _messagePublisher.PublishAsync(new CohortCreated(newCommitment.EmployerAcc newCommitment.Id)); } - private async Task CreateCommitment(CreateCommitmentCommand message, Relationship relationshipToCreate) + private async Task CreateCommitment(CreateCommitmentCommand message) { var newCommitment = message.Commitment; newCommitment.LastAction = LastAction.None; - newCommitment.Id = await _commitmentRepository.Create(newCommitment, relationshipToCreate); + newCommitment.Id = await _commitmentRepository.Create(newCommitment); await _commitmentRepository.UpdateCommitmentReference(newCommitment.Id, _hashingService.HashValue(newCommitment.Id)); return newCommitment; @@ -110,41 +100,5 @@ private async Task CreateMessageIfNeeded(long commitmentId, CreateCommitmentComm await _commitmentRepository.SaveMessage(commitmentId, message); } - - private async Task PublishRelationshipCreatedEventIfNeeded(Relationship relationship) - { - if (relationship == null) return; - await _messagePublisher.PublishAsync(CreateRelationshipCreatedEvent(relationship)); - } - - private static Relationship CreateRelationshipFromCommitment(Commitment commitment) - { - return new Relationship - { - EmployerAccountId = commitment.EmployerAccountId, - LegalEntityId = commitment.LegalEntityId, - LegalEntityName = commitment.LegalEntityName, - LegalEntityAddress = commitment.LegalEntityAddress, - LegalEntityOrganisationType = commitment.LegalEntityOrganisationType, - ProviderId = commitment.ProviderId.Value, - ProviderName = commitment.ProviderName - }; - } - - private static RelationshipCreated CreateRelationshipCreatedEvent(Relationship entity) - { - return new RelationshipCreated(new Api.Types.Relationship - { - EmployerAccountId = entity.EmployerAccountId, - Id = entity.Id, - LegalEntityId = entity.LegalEntityId, - LegalEntityName = entity.LegalEntityName, - LegalEntityAddress = entity.LegalEntityAddress, - LegalEntityOrganisationType = entity.LegalEntityOrganisationType, - ProviderId = entity.ProviderId, - ProviderName = entity.ProviderName, - Verified = entity.Verified - }); - } } } diff --git a/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommand.cs b/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommand.cs deleted file mode 100644 index 3c143e9dc4..0000000000 --- a/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommand.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MediatR; -using SFA.DAS.Commitments.Domain; - -namespace SFA.DAS.Commitments.Application.Commands.VerifyRelationship -{ - public sealed class VerifyRelationshipCommand : IAsyncRequest - { - public Caller Caller { get; set; } - public long EmployerAccountId { get; set; } - public long ProviderId { get; set; } - public string LegalEntityId { get; set; } - public bool? Verified { get; set; } - public string UserId { get; set; } - } -} diff --git a/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommandHandler.cs b/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommandHandler.cs deleted file mode 100644 index 8d0a4c1243..0000000000 --- a/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipCommandHandler.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Threading.Tasks; -using FluentValidation; -using MediatR; -using SFA.DAS.Commitments.Domain.Data; -using SFA.DAS.Commitments.Domain.Interfaces; -using SFA.DAS.Commitments.Events; -using SFA.DAS.Messaging.Interfaces; - -namespace SFA.DAS.Commitments.Application.Commands.VerifyRelationship -{ - public sealed class VerifyRelationshipCommandHandler: AsyncRequestHandler - { - private readonly IRelationshipRepository _relationshipRepository; - private readonly VerifyRelationshipValidator _validator; - private readonly ICommitmentsLogger _logger; - private readonly IMessagePublisher _messagePublisher; - - public VerifyRelationshipCommandHandler(IRelationshipRepository relationshipRepository, VerifyRelationshipValidator validator, ICommitmentsLogger logger, IMessagePublisher messagePublisher) - { - _relationshipRepository = relationshipRepository; - _validator = validator; - _logger = logger; - _messagePublisher = messagePublisher; - } - - protected override async Task HandleCore(VerifyRelationshipCommand message) - { - _logger.Info($"Provider {message.ProviderId} has called VerifyRelationshipCommand for Employer {message.EmployerAccountId}, LegalEntity {message.LegalEntityId}"); - - var validationResult = _validator.Validate(message); - - if (!validationResult.IsValid) - throw new ValidationException(validationResult.Errors); - - await Task.WhenAll(_relationshipRepository.VerifyRelationship(message.EmployerAccountId, message.ProviderId, - message.LegalEntityId, message.Verified.Value), - PublishRelationshipVerifiedEvent(message.ProviderId, message.EmployerAccountId, message.LegalEntityId, message.Verified.Value)); - } - - private async Task PublishRelationshipVerifiedEvent(long providerId, long employerAccountId, string legalEntityId, bool? verified) - { - await _messagePublisher.PublishAsync(new RelationshipVerified(providerId, employerAccountId, legalEntityId, verified)); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipValidator.cs b/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipValidator.cs deleted file mode 100644 index 6e4c026f9b..0000000000 --- a/src/SFA.DAS.Commitments.Application/Commands/VerifyRelationship/VerifyRelationshipValidator.cs +++ /dev/null @@ -1,16 +0,0 @@ -using FluentValidation; - -namespace SFA.DAS.Commitments.Application.Commands.VerifyRelationship -{ - public class VerifyRelationshipValidator : AbstractValidator - { - public VerifyRelationshipValidator() - { - RuleFor(x => x.EmployerAccountId).NotEmpty(); - RuleFor(x => x.ProviderId).NotEmpty(); - RuleFor(x => x.LegalEntityId).NotEmpty(); - RuleFor(x => x.UserId).NotEmpty(); - RuleFor(x => x.Verified).NotEmpty(); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipQueryHandler.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipQueryHandler.cs deleted file mode 100644 index 90b5f48d0f..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipQueryHandler.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Threading.Tasks; -using FluentValidation; -using MediatR; -using SFA.DAS.Commitments.Domain.Data; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationship -{ - public sealed class GetRelationshipQueryHandler : IAsyncRequestHandler - { - private readonly IRelationshipRepository _relationshipRepository; - private readonly AbstractValidator _validator; - - public GetRelationshipQueryHandler(IRelationshipRepository relationshipRepository, AbstractValidator validator) - { - _relationshipRepository = relationshipRepository; - _validator = validator; - } - - public async Task Handle(GetRelationshipRequest message) - { - var validationResult = _validator.Validate(message); - - if (!validationResult.IsValid) - throw new ValidationException(validationResult.Errors); - - var entity = await _relationshipRepository.GetRelationship(message.EmployerAccountId, message.ProviderId, - message.LegalEntityId); - - if (entity == null) - { - return new GetRelationshipResponse(); - } - - var result = new GetRelationshipResponse { Data = entity }; - - return result; - } - - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipRequest.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipRequest.cs deleted file mode 100644 index c255579789..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using MediatR; -using SFA.DAS.Commitments.Domain; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationship -{ - public class GetRelationshipRequest : IAsyncRequest - { - public Caller Caller { get; set; } - public long EmployerAccountId { get; set; } - public long ProviderId { get; set; } - public string LegalEntityId { get; set; } - - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipResponse.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipResponse.cs deleted file mode 100644 index 552c6a480c..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationship -{ - public sealed class GetRelationshipResponse: QueryResponse - { - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipValidator.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipValidator.cs deleted file mode 100644 index 0a6b440a1c..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationship/GetRelationshipValidator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using FluentValidation; -using SFA.DAS.Commitments.Domain; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationship -{ - public sealed class GetRelationshipValidator : AbstractValidator - { - public GetRelationshipValidator() - { - RuleFor(x => x.EmployerAccountId) - .NotEmpty() - .WithMessage("EmployerAccountId must be specified"); - - RuleFor(x => x.ProviderId) - .NotEmpty() - .WithMessage("ProviderId must be specified"); - - RuleFor(x => x.LegalEntityId) - .NotEmpty() - .WithMessage("LegalEntityId must be specified"); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentQueryHandler.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentQueryHandler.cs deleted file mode 100644 index 69130b2331..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentQueryHandler.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Threading.Tasks; -using FluentValidation; -using MediatR; -using SFA.DAS.Commitments.Application.Exceptions; -using SFA.DAS.Commitments.Domain.Data; -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment -{ - public sealed class GetRelationshipByCommitmentQueryHandler : - IAsyncRequestHandler - { - private readonly ICommitmentRepository _commitmentRepository; - private readonly IRelationshipRepository _relationshipRepository; - private readonly AbstractValidator _validator; - - public GetRelationshipByCommitmentQueryHandler(ICommitmentRepository commitmentRepository, - AbstractValidator validator, - IRelationshipRepository relationshipRepository) - { - _commitmentRepository = commitmentRepository; - _validator = validator; - _relationshipRepository = relationshipRepository; - } - - public async Task Handle(GetRelationshipByCommitmentRequest message) - { - var validationResult = _validator.Validate(message); - - if (!validationResult.IsValid) - throw new ValidationException(validationResult.Errors); - - var commitment = await _commitmentRepository.GetCommitmentById(message.CommitmentId); - - CheckAuthorisation(message.Caller.Id, commitment); - - var entity = await _relationshipRepository.GetRelationship(commitment.EmployerAccountId, - commitment.ProviderId.Value, commitment.LegalEntityId); - - if (entity == null) - { - return new GetRelationshipByCommitmentResponse(); - } - - return new GetRelationshipByCommitmentResponse - { - Data = entity - }; - } - - private static void CheckAuthorisation(long providerId, Commitment commitment) - { - if (providerId != commitment.ProviderId.Value) - { - throw new UnauthorizedException($"Provider {providerId} not authorised to access commitment {commitment.Id}"); - } - } - } -} \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentRequest.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentRequest.cs deleted file mode 100644 index 9ffafd0da1..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using MediatR; - -using SFA.DAS.Commitments.Domain; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment -{ - public sealed class GetRelationshipByCommitmentRequest : IAsyncRequest - { - public Caller Caller { get; set; } - public long ProviderId { get; set; } - public long CommitmentId { get; set; } - - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentResponse.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentResponse.cs deleted file mode 100644 index d09097e135..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment -{ - public class GetRelationshipByCommitmentResponse: QueryResponse - { - } -} diff --git a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentValidator.cs b/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentValidator.cs deleted file mode 100644 index 60299c4a19..0000000000 --- a/src/SFA.DAS.Commitments.Application/Queries/GetRelationshipByCommitment/GetRelationshipByCommitmentValidator.cs +++ /dev/null @@ -1,18 +0,0 @@ -using FluentValidation; - -namespace SFA.DAS.Commitments.Application.Queries.GetRelationshipByCommitment -{ - public sealed class GetRelationshipByCommitmentValidator : AbstractValidator - { - public GetRelationshipByCommitmentValidator() - { - RuleFor(x => x.ProviderId) - .NotEmpty() - .WithMessage("ProviderId must be specified"); - - RuleFor(x => x.CommitmentId) - .NotEmpty() - .WithMessage("CommitmentId must be specified"); - } - } -} diff --git a/src/SFA.DAS.Commitments.Application/SFA.DAS.Commitments.Application.csproj b/src/SFA.DAS.Commitments.Application/SFA.DAS.Commitments.Application.csproj index 70683fbf2b..bb693f5c98 100644 --- a/src/SFA.DAS.Commitments.Application/SFA.DAS.Commitments.Application.csproj +++ b/src/SFA.DAS.Commitments.Application/SFA.DAS.Commitments.Application.csproj @@ -166,9 +166,6 @@ - - - @@ -235,14 +232,6 @@ - - - - - - - - diff --git a/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj b/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj index 96231bebf6..07ff1b2920 100644 --- a/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj +++ b/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj @@ -77,10 +77,6 @@ - - - - @@ -137,7 +133,6 @@ - diff --git a/src/SFA.DAS.Commitments.Database/StoredProcedures/CreateRelationship.sql b/src/SFA.DAS.Commitments.Database/StoredProcedures/CreateRelationship.sql deleted file mode 100644 index fd594ae214..0000000000 --- a/src/SFA.DAS.Commitments.Database/StoredProcedures/CreateRelationship.sql +++ /dev/null @@ -1,40 +0,0 @@ -CREATE PROCEDURE [dbo].[CreateRelationship] -( - @ProviderId BIGINT, - @ProviderName NVARCHAR(100), - @EmployerAccountId BIGINT, - @LegalEntityId NVARCHAR(50), - @LegalEntityName NVARCHAR(100), - @LegalEntityAddress NVARCHAR(256), - @LegalEntityOrganisationType TINYINT, - @Verified BIT, - @CreatedOn DATETIME -) -as - -insert into [dbo].[Relationship] -( - ProviderId, - ProviderName, - EmployerAccountId, - LegalEntityId, - LegalEntityName, - LegalEntityAddress, - LegalEntityOrganisationType, - Verified, - CreatedOn -) -values -( - @ProviderId, - @ProviderName, - @EmployerAccountId, - @LegalEntityId, - @LegalEntityName, - @LegalEntityAddress, - @LegalEntityOrganisationType, - @Verified, - @CreatedOn -) - -SELECT SCOPE_IDENTITY() \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Database/StoredProcedures/GetRelationship.sql b/src/SFA.DAS.Commitments.Database/StoredProcedures/GetRelationship.sql deleted file mode 100644 index 528cf91a6b..0000000000 --- a/src/SFA.DAS.Commitments.Database/StoredProcedures/GetRelationship.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE PROCEDURE [dbo].[GetRelationship] - @EmployerAccountId BIGINT, - @ProviderId BIGINT, - @LegalEntityId nvarchar(50) -AS - - select - Id, - ProviderId, - ProviderName, - EmployerAccountId, - LegalEntityId, - LegalEntityName, - LegalEntityAddress, - LegalEntityOrganisationType, - Verified - from - [dbo].[Relationship] - where - EmployerAccountId = @EmployerAccountId - and ProviderId = @ProviderId - and LegalEntityId = @LegalEntityId - diff --git a/src/SFA.DAS.Commitments.Database/StoredProcedures/VerifyRelationship.sql b/src/SFA.DAS.Commitments.Database/StoredProcedures/VerifyRelationship.sql deleted file mode 100644 index 739f3e76d8..0000000000 --- a/src/SFA.DAS.Commitments.Database/StoredProcedures/VerifyRelationship.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE PROCEDURE [dbo].[VerifyRelationship] - @EmployerAccountId BIGINT, - @ProviderId BIGINT, - @LegalEntityId nvarchar(50), - @Verified BIT -AS - - update - [dbo].Relationship - set Verified = @Verified - where - EmployerAccountId = @EmployerAccountId - and ProviderId = @ProviderId - and LegalEntityId = @LegalEntityId diff --git a/src/SFA.DAS.Commitments.Database/Tables/Relationship.sql b/src/SFA.DAS.Commitments.Database/Tables/Relationship.sql deleted file mode 100644 index 23d9baf22f..0000000000 --- a/src/SFA.DAS.Commitments.Database/Tables/Relationship.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE [dbo].[Relationship] -( - [Id] BIGINT NOT NULL PRIMARY KEY IDENTITY, - [ProviderId] BIGINT NOT NULL, - [ProviderName] NVARCHAR(100) NULL, - [EmployerAccountId] BIGINT NOT NULL, - [LegalEntityId] NVARCHAR(50) NOT NULL, - [LegalEntityName] NVARCHAR(100) NOT NULL, - [LegalEntityAddress] NVARCHAR(256) NOT NULL, - [LegalEntityOrganisationType] TINYINT NOT NULL, - [Verified] BIT NULL, - [CreatedOn] DATETIME NULL, - CONSTRAINT UQ_Relationship UNIQUE (EmployerAccountId,ProviderId,LegalEntityId) -) -GO - -CREATE NONCLUSTERED INDEX [IX_Relationship_Employer_Provider_LegalEntity] ON [dbo].[Relationship] ([EmployerAccountId], [ProviderId], [LegalEntityId]) \ No newline at end of file diff --git a/src/SFA.DAS.Commitments.Domain/Data/ICommitmentRepository.cs b/src/SFA.DAS.Commitments.Domain/Data/ICommitmentRepository.cs index 801b1f6010..c51e407e57 100644 --- a/src/SFA.DAS.Commitments.Domain/Data/ICommitmentRepository.cs +++ b/src/SFA.DAS.Commitments.Domain/Data/ICommitmentRepository.cs @@ -7,7 +7,7 @@ namespace SFA.DAS.Commitments.Domain.Data { public interface ICommitmentRepository { - Task Create(Commitment commitment, Relationship relationship = null); + Task Create(Commitment commitment); Task> GetCommitmentsByProvider(long providerId); Task> GetCommitmentsByEmployer(long accountId); Task> GetCommitmentAgreementsForProvider(long providerId); diff --git a/src/SFA.DAS.Commitments.Domain/Data/IRelationshipRepository.cs b/src/SFA.DAS.Commitments.Domain/Data/IRelationshipRepository.cs deleted file mode 100644 index bf3d904d23..0000000000 --- a/src/SFA.DAS.Commitments.Domain/Data/IRelationshipRepository.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Threading.Tasks; -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Domain.Data -{ - public interface IRelationshipRepository - { - Task GetRelationship(long employerAccountId, long providerId, string legalEntityCode); - Task VerifyRelationship(long employerAccountId, long providerId, string legalEntityCode, bool verified); - } -} diff --git a/src/SFA.DAS.Commitments.Domain/Entities/Relationship.cs b/src/SFA.DAS.Commitments.Domain/Entities/Relationship.cs deleted file mode 100644 index f0a85701d2..0000000000 --- a/src/SFA.DAS.Commitments.Domain/Entities/Relationship.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace SFA.DAS.Commitments.Domain.Entities -{ - public class Relationship - { - public long Id { get; set; } - public long EmployerAccountId { get; set; } - public string LegalEntityId { get; set; } - public string LegalEntityName { get; set; } - public string LegalEntityAddress { get; set; } - public SFA.DAS.Common.Domain.Types.OrganisationType LegalEntityOrganisationType { get; set; } - public long ProviderId { get; set; } - public string ProviderName { get; set; } - public bool? Verified { get; set; } - } -} diff --git a/src/SFA.DAS.Commitments.Domain/SFA.DAS.Commitments.Domain.csproj b/src/SFA.DAS.Commitments.Domain/SFA.DAS.Commitments.Domain.csproj index b88f1fd9e3..12492f0863 100644 --- a/src/SFA.DAS.Commitments.Domain/SFA.DAS.Commitments.Domain.csproj +++ b/src/SFA.DAS.Commitments.Domain/SFA.DAS.Commitments.Domain.csproj @@ -93,7 +93,6 @@ - @@ -143,7 +142,6 @@ - diff --git a/src/SFA.DAS.Commitments.Events/RelationshipCreated.cs b/src/SFA.DAS.Commitments.Events/RelationshipCreated.cs deleted file mode 100644 index 24e7d91f5c..0000000000 --- a/src/SFA.DAS.Commitments.Events/RelationshipCreated.cs +++ /dev/null @@ -1,22 +0,0 @@ -using SFA.DAS.Commitments.Api.Types; -using SFA.DAS.Messaging.Attributes; - -namespace SFA.DAS.Commitments.Events -{ - [MessageGroup("relationship_created")] - public class RelationshipCreated - { - public RelationshipCreated() - { - - } - - public RelationshipCreated(Relationship relationship) - { - Relationship = relationship; - } - - public Relationship Relationship { get; set; } - - } -} diff --git a/src/SFA.DAS.Commitments.Events/RelationshipVerified.cs b/src/SFA.DAS.Commitments.Events/RelationshipVerified.cs deleted file mode 100644 index 9844fea5b8..0000000000 --- a/src/SFA.DAS.Commitments.Events/RelationshipVerified.cs +++ /dev/null @@ -1,26 +0,0 @@ -using SFA.DAS.Messaging.Attributes; - -namespace SFA.DAS.Commitments.Events -{ - [MessageGroup("relationship_verified")] - public class RelationshipVerified - { - public RelationshipVerified() - { - - } - - public RelationshipVerified(long providerId, long employerAccountId, string legalEntityId, bool? verified) - { - ProviderId = providerId; - EmployerAccountId = employerAccountId; - LegalEntityId = legalEntityId; - Verified = verified; - } - - public long ProviderId { get; set; } - public long EmployerAccountId { get; set; } - public string LegalEntityId { get; set; } - public bool? Verified { get; set; } - } -} diff --git a/src/SFA.DAS.Commitments.Events/SFA.DAS.Commitments.Events.csproj b/src/SFA.DAS.Commitments.Events/SFA.DAS.Commitments.Events.csproj index d18122efb4..1fa1e9e79a 100644 --- a/src/SFA.DAS.Commitments.Events/SFA.DAS.Commitments.Events.csproj +++ b/src/SFA.DAS.Commitments.Events/SFA.DAS.Commitments.Events.csproj @@ -80,8 +80,6 @@ - - diff --git a/src/SFA.DAS.Commitments.Infrastructure/Data/CommitmentRepository.cs b/src/SFA.DAS.Commitments.Infrastructure/Data/CommitmentRepository.cs index 45d74d390c..c50332dc99 100644 --- a/src/SFA.DAS.Commitments.Infrastructure/Data/CommitmentRepository.cs +++ b/src/SFA.DAS.Commitments.Infrastructure/Data/CommitmentRepository.cs @@ -20,20 +20,17 @@ public class CommitmentRepository : BaseRepository, ICommitmentRepository { private readonly ICommitmentsLogger _logger; private readonly ICurrentDateTime _currentDateTime; - private readonly IRelationshipTransactions _relationshipTransactions; public CommitmentRepository(string databaseConnectionString, ICommitmentsLogger logger, - ICurrentDateTime currentDateTime, - IRelationshipTransactions relationshipTransactions) : base(databaseConnectionString, + ICurrentDateTime currentDateTime) : base(databaseConnectionString, logger.BaseLogger) { _logger = logger; _currentDateTime = currentDateTime; - _relationshipTransactions = relationshipTransactions; } - public async Task Create(Commitment commitment, Relationship relationship = null) + public async Task Create(Commitment commitment) { _logger.Debug($"Creating commitment with ref: {commitment.Reference}", accountId: commitment.EmployerAccountId, providerId: commitment.ProviderId); @@ -73,11 +70,6 @@ public async Task Create(Commitment commitment, Relationship relationship commandType: CommandType.Text, transaction: trans)).Single(); - if (relationship != null) - { - await _relationshipTransactions.CreateRelationship(connection, trans, relationship); - } - trans.Commit(); return commitmentId; } diff --git a/src/SFA.DAS.Commitments.Infrastructure/Data/RelationshipRepository.cs b/src/SFA.DAS.Commitments.Infrastructure/Data/RelationshipRepository.cs deleted file mode 100644 index fcdbbbf794..0000000000 --- a/src/SFA.DAS.Commitments.Infrastructure/Data/RelationshipRepository.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using Dapper; -using SFA.DAS.Commitments.Domain.Data; -using SFA.DAS.Commitments.Domain.Entities; -using SFA.DAS.Commitments.Domain.Interfaces; -using SFA.DAS.Sql.Client; - -namespace SFA.DAS.Commitments.Infrastructure.Data -{ - public class RelationshipRepository : BaseRepository, IRelationshipRepository - { - public RelationshipRepository(string databaseConnectionString, ICommitmentsLogger logger) : base(databaseConnectionString,logger.BaseLogger) - { - } - - public async Task GetRelationship(long employerAccountId, long providerId, string legalEntityCode) - { - return await WithConnection(async connection => - { - var parameters = new DynamicParameters(); - parameters.Add("@EmployerAccountId", employerAccountId); - parameters.Add("@ProviderId", providerId); - parameters.Add("@LegalEntityId", legalEntityCode); - - var results = await connection.QueryAsync( - sql: $"[dbo].[GetRelationship]", - param: parameters, - commandType: CommandType.StoredProcedure); - - return results.FirstOrDefault(); - }); - } - - public async Task VerifyRelationship(long employerAccountId, long providerId, string legalEntityCode, bool verified) - { - await WithConnection(async connection => - { - var parameters = new DynamicParameters(); - parameters.Add("@EmployerAccountId", employerAccountId); - parameters.Add("@ProviderId", providerId); - parameters.Add("@LegalEntityId", legalEntityCode); - parameters.Add("@Verified", verified); - - return await connection.ExecuteAsync( - sql: $"[dbo].[VerifyRelationship]", - param: parameters, - commandType: CommandType.StoredProcedure); - }); - } - } -} diff --git a/src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/IRelationshipTransactions.cs b/src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/IRelationshipTransactions.cs deleted file mode 100644 index dee8e0a5e1..0000000000 --- a/src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/IRelationshipTransactions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Data; -using System.Threading.Tasks; -using SFA.DAS.Commitments.Domain.Entities; - -namespace SFA.DAS.Commitments.Infrastructure.Data.Transactions -{ - public interface IRelationshipTransactions - { - Task CreateRelationship(IDbConnection connection, IDbTransaction trans, Relationship relationship); - } -} diff --git a/src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/RelationshipTransactions.cs b/src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/RelationshipTransactions.cs deleted file mode 100644 index 3ba18117d0..0000000000 --- a/src/SFA.DAS.Commitments.Infrastructure/Data/Transactions/RelationshipTransactions.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Data; -using System.Threading.Tasks; -using Dapper; -using SFA.DAS.Commitments.Domain.Entities; -using SFA.DAS.Commitments.Domain.Interfaces; - -namespace SFA.DAS.Commitments.Infrastructure.Data.Transactions -{ - public class RelationshipTransactions : IRelationshipTransactions - { - private readonly ICommitmentsLogger _logger; - private readonly ICurrentDateTime _currentDateTime; - - public RelationshipTransactions(ICommitmentsLogger logger, ICurrentDateTime currentDateTime) - { - _logger = logger; - _currentDateTime = currentDateTime; - } - - public async Task CreateRelationship(IDbConnection connection, IDbTransaction trans, Relationship relationship) - { - _logger.Debug( - $"Creating relationship between Provider {relationship.ProviderId}, Employer {relationship.EmployerAccountId}, Legal Entity: {relationship.LegalEntityId}"); - - var parameters = new DynamicParameters(); - parameters.Add("@ProviderId", relationship.ProviderId, DbType.Int64); - parameters.Add("@ProviderName", relationship.ProviderName, DbType.String); - parameters.Add("@LegalEntityId", relationship.LegalEntityId, DbType.String); - parameters.Add("@LegalEntityName", relationship.LegalEntityName, DbType.String); - parameters.Add("@LegalEntityAddress", relationship.LegalEntityAddress, DbType.String); - parameters.Add("@LegalEntityOrganisationType", relationship.LegalEntityOrganisationType, DbType.Int16); - parameters.Add("@EmployerAccountId", relationship.EmployerAccountId, DbType.String); - parameters.Add("@Verified", relationship.Verified, DbType.Boolean); - parameters.Add("@CreatedOn", _currentDateTime.Now, DbType.DateTime); - - return await connection.ExecuteAsync( - sql: "[dbo].[CreateRelationship]", - param: parameters, - transaction: trans, - commandType: CommandType.StoredProcedure); - } - } -} diff --git a/src/SFA.DAS.Commitments.Infrastructure/SFA.DAS.Commitments.Infrastructure.csproj b/src/SFA.DAS.Commitments.Infrastructure/SFA.DAS.Commitments.Infrastructure.csproj index 348ba59df7..e23430d694 100644 --- a/src/SFA.DAS.Commitments.Infrastructure/SFA.DAS.Commitments.Infrastructure.csproj +++ b/src/SFA.DAS.Commitments.Infrastructure/SFA.DAS.Commitments.Infrastructure.csproj @@ -202,14 +202,11 @@ - - -