Skip to content

Commit

Permalink
Merge branch 'master' into CON-1518-Triage-Questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Howes committed Apr 23, 2020
2 parents 424b5c6 + 6399809 commit 60da8cd
Show file tree
Hide file tree
Showing 78 changed files with 1,249 additions and 1,317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
<Build Include="StoredProcedures\GetPaye_ByRef.sql" />
<Build Include="StoredProcedures\UpdatePayeName_ByRef.sql" />
<Build Include="StoredProcedures\RemoveLegalEntityFromAccount.sql" />
<Build Include="StoredProcedures\GetEmployerAgreementsToRemove_ByAccountId.sql" />
<Build Include="Tables\UserAccountSettings.sql" />
<Build Include="StoredProcedures\RemoveMembership.sql" />
<Build Include="StoredProcedures\GetUserAccountSettings.sql" />
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/SFA.DAS.EAS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFA.DAS.EmployerAccounts.Ap
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFA.DAS.EmployerAccounts.Api.IntegrationTests", "SFA.DAS.EmployerAccounts.Api.IntegrationTests\SFA.DAS.EmployerAccounts.Api.IntegrationTests.csproj", "{BD68EB2C-A486-42B2-8685-776B164FD860}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFA.DAS.EmployerFinance.MessageHandlers.TestHarness", "SFA.DAS.EmployerFinance.MessageHandlers.TestHarness\SFA.DAS.EmployerFinance.MessageHandlers.TestHarness.csproj", "{73080F2E-1875-4DBC-BE84-381E2FD603D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFA.DAS.EmployerFinance.MessageHandlers.TestHarness", "SFA.DAS.EmployerFinance.MessageHandlers.TestHarness\SFA.DAS.EmployerFinance.MessageHandlers.TestHarness.csproj", "{73080F2E-1875-4DBC-BE84-381E2FD603D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using SFA.DAS.EmployerAccounts.Data;
using SFA.DAS.EmployerAccounts.Events.Agreement;
using SFA.DAS.EmployerAccounts.Factories;
using SFA.DAS.EmployerAccounts.MarkerInterfaces;
using SFA.DAS.EmployerAccounts.Messages.Events;
using SFA.DAS.EmployerAccounts.Models.Account;
using SFA.DAS.EmployerAccounts.Models.AccountTeam;
using SFA.DAS.EmployerAccounts.Models.EmployerAgreement;
using SFA.DAS.Events.Api.Types;
Expand All @@ -33,6 +35,7 @@ public class WhenIRemoveALegalEntity
private RemoveLegalEntityCommand _command;
private Mock<IMediator> _mediator;
private Mock<IHashingService> _hashingService;
private Mock<IAccountLegalEntityPublicHashingService> _accountLegalEntityPublicHashingService;
private Mock<IGenericEventFactory> _genericEventHandler;
private Mock<IEmployerAgreementEventFactory> _employerAgreementEventFactory;
private Mock<IMembershipRepository> _membershipRepository;
Expand All @@ -48,6 +51,7 @@ public class WhenIRemoveALegalEntity
private EmployerAgreementView _expectedAgreement;
private const long ExpectedEmployerAgreementId = 5533678;
private const string ExpectedHashedEmployerAgreementId = "FGDFH45645";
private const string ExpectedHashedAccountLegalEntityId = "HDHFFS";

[SetUp]
public void Arrange()
Expand All @@ -60,6 +64,17 @@ public void Arrange()
_mediator = new Mock<IMediator>();

_repository = new Mock<IEmployerAgreementRepository>();
_repository.Setup(r => r.GetAccountLegalEntityAgreements(ExpectedAccountLegalEntityId))
.ReturnsAsync(new List<EmployerAgreement>
{
new EmployerAgreement
{
AccountLegalEntityId = ExpectedAccountLegalEntityId,
TemplateId = 1,
Id = ExpectedEmployerAgreementId
}
});

_expectedAgreement = new EmployerAgreementView
{
AccountLegalEntityId = ExpectedAccountLegalEntityId,
Expand All @@ -70,10 +85,14 @@ public void Arrange()
};

_repository.Setup(r => r.GetEmployerAgreement(ExpectedEmployerAgreementId)).ReturnsAsync(_expectedAgreement);

_hashingService = new Mock<IHashingService>();
_hashingService.Setup(x => x.DecodeValue(ExpectedHashedAccountId)).Returns(ExpectedAccountId);
_hashingService.Setup(x => x.DecodeValue(ExpectedHashedEmployerAgreementId)).Returns(ExpectedEmployerAgreementId);
_hashingService.Setup(x => x.HashValue(ExpectedEmployerAgreementId)).Returns(ExpectedHashedEmployerAgreementId);

_accountLegalEntityPublicHashingService = new Mock<IAccountLegalEntityPublicHashingService>();
_accountLegalEntityPublicHashingService.Setup(x => x.DecodeValue(ExpectedHashedAccountLegalEntityId)).Returns(ExpectedAccountLegalEntityId);

_employerAgreementEventFactory = new Mock<IEmployerAgreementEventFactory>();
_employerAgreementEventFactory.Setup(x => x.RemoveAgreementEvent(ExpectedHashedEmployerAgreementId)).Returns(new AgreementRemovedEvent { HashedAgreementId = ExpectedHashedEmployerAgreementId });
Expand All @@ -98,13 +117,14 @@ public void Arrange()
}
});

_command = new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId = _expectedUserId, HashedLegalAgreementId = ExpectedHashedEmployerAgreementId };
_command = new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId = _expectedUserId, HashedAccountLegalEntityId = ExpectedHashedAccountLegalEntityId };

_handler = new RemoveLegalEntityCommandHandler(
_validator.Object,
_logger.Object,
_repository.Object,
_mediator.Object,
_accountLegalEntityPublicHashingService.Object,
_hashingService.Object,
_genericEventHandler.Object,
_employerAgreementEventFactory.Object,
Expand Down Expand Up @@ -144,6 +164,9 @@ public async Task ThenTheRepositoryIsCalled()
_validator.Verify(x => x.ValidateAsync(It.Is<RemoveLegalEntityCommand>(c =>
c.HashedAccountId.Equals(ExpectedHashedAccountId)
&& c.UserId.Equals(_expectedUserId))));

_repository.Verify(x => x.GetAccountLegalEntityAgreements(ExpectedAccountLegalEntityId));
_repository.Verify(x => x.GetEmployerAgreement(ExpectedEmployerAgreementId));
_repository.Verify(x => x.RemoveLegalEntityFromAccount(ExpectedEmployerAgreementId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public async Task ThenTheCommandIsCheckedToSeeIfAllFieldsArePopulatedAndFalseIsR
Assert.IsFalse(actual.IsValid());
Assert.Contains(new KeyValuePair<string,string>("HashedAccountId", "HashedAccountId has not been supplied"), actual.ValidationDictionary);
Assert.Contains(new KeyValuePair<string,string>("UserId","UserId has not been supplied"), actual.ValidationDictionary);
Assert.Contains(new KeyValuePair<string,string>("HashedLegalAgreementId", "HashedLegalAgreementId has not been supplied"), actual.ValidationDictionary);
Assert.Contains(new KeyValuePair<string,string>("HashedAccountLegalEntityId", "HashedAccountLegalEntityId has not been supplied"), actual.ValidationDictionary);
_membershipRepository.Verify(x=>x.GetCaller(It.IsAny<string>(),It.IsAny<string>()), Times.Never);
}

[Test]
public async Task ThenTheUserIsCheckedToSeeIfTheyAreConnectedToTheAccount()
{
//Act
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand {HashedAccountId = ExpectedHashedAccountId, UserId = "TGB678", HashedLegalAgreementId = "ewr" });
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand {HashedAccountId = ExpectedHashedAccountId, UserId = "TGB678", HashedAccountLegalEntityId = "ewr" });

//Assert
Assert.IsTrue(actual.IsUnauthorized);
Expand All @@ -82,7 +82,7 @@ public async Task ThenTheUserIsCheckedToSeeIfTheyAreConnectedToTheAccount()
public async Task ThenTheUserIsCheckedToSeeIfTheyAreAnOwnerOnTheAccount()
{
//Act
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId = ExpectedNonOwnerUserId, HashedLegalAgreementId = "fdgd" });
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId = ExpectedNonOwnerUserId, HashedAccountLegalEntityId = "fdgd" });

//Assert
Assert.IsTrue(actual.IsUnauthorized);
Expand All @@ -92,7 +92,7 @@ public async Task ThenTheUserIsCheckedToSeeIfTheyAreAnOwnerOnTheAccount()
public async Task ThenTrueIsReturnedIfTheFieldsArePopulatedAndTheUserIsAnAccountOwner()
{
//Act
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId= ExpectedUserId, HashedLegalAgreementId = ExpectedHashedAgreementId });
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId= ExpectedUserId, HashedAccountLegalEntityId = ExpectedHashedLegalEntityId });

//Assert
Assert.IsTrue(actual.IsValid());
Expand All @@ -111,11 +111,11 @@ public async Task ThenIfThereIsOnlyOneLegalEntityConnectedToTheAccountThenFalseI
});

//Act
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId = ExpectedUserId, HashedLegalAgreementId = ExpectedHashedAgreementId });
var actual = await _removeLegalEntityCommandValidator.ValidateAsync(new RemoveLegalEntityCommand { HashedAccountId = ExpectedHashedAccountId, UserId = ExpectedUserId, HashedAccountLegalEntityId = ExpectedHashedLegalEntityId });

//Assert
Assert.IsFalse(actual.IsValid());
Assert.Contains(new KeyValuePair<string, string>("HashedLegalAgreementId", "There must be at least one legal entity on the account"), actual.ValidationDictionary);
Assert.Contains(new KeyValuePair<string, string>("HashedAccountLegalEntityId", "There must be at least one legal entity on the account"), actual.ValidationDictionary);
}
}
}

This file was deleted.

Loading

0 comments on commit 60da8cd

Please sign in to comment.