-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7cf270
commit 69d1e90
Showing
16 changed files
with
282 additions
and
270 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...yerAccounts.UnitTests/Queries/GetOrganisationAgreements/WhenIGetOrganisationAgreements.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using SFA.DAS.EmployerAccounts.Queries.GetOrganisationAgreements; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.EmployerAccounts.Interfaces; | ||
using SFA.DAS.HashingService; | ||
using SFA.DAS.Validation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using SFA.DAS.EmployerAccounts.Data; | ||
using SFA.DAS.EmployerAccounts.MarkerInterfaces; | ||
using AutoMapper; | ||
using SFA.DAS.EmployerAccounts.Models.Account; | ||
using SFA.DAS.EmployerAccounts.Dtos; | ||
using SFA.DAS.Common.Domain.Types; | ||
|
||
namespace SFA.DAS.EmployerAccounts.UnitTests.Queries.GetOrganisationAgreements | ||
{ | ||
public class WhenIGetOrganisationAgreements : QueryBaseTest<GetOrganisationAgreementsQueryHandler, GetOrganisationAgreementsRequest, GetOrganisationAgreementsResponse> | ||
{ | ||
public override GetOrganisationAgreementsRequest Query { get; set; } | ||
public override GetOrganisationAgreementsQueryHandler RequestHandler { get; set; } | ||
public override Mock<IValidator<GetOrganisationAgreementsRequest>> RequestValidator { get; set; } | ||
private Mock<IEmployerAgreementRepository> _mockEmployerAgreementRepository; | ||
private Mock<IAccountLegalEntityPublicHashingService> _mockAccountLegalEntityPublicHashingService; | ||
private Mock<IHashingService> _mockhashingService; | ||
private Mock<IReferenceDataService> _mockreferenceDataService; | ||
private Mock<IMapper> _mockmapper; | ||
private long _accountLegelEntityId = 123; | ||
private string hashedId = "ABC123"; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
SetUp(); | ||
|
||
_mockAccountLegalEntityPublicHashingService = new Mock<IAccountLegalEntityPublicHashingService>(); | ||
_mockAccountLegalEntityPublicHashingService.Setup(m => m.DecodeValue(It.IsAny<string>())).Returns(_accountLegelEntityId); | ||
|
||
_mockEmployerAgreementRepository = new Mock<IEmployerAgreementRepository>(); | ||
_mockEmployerAgreementRepository.Setup(m => m.GetOrganisationAgreement(It.IsAny<long>())).ReturnsAsync | ||
(new AccountLegalEntity { | ||
|
||
LegalEntity = new LegalEntity { Id=1, Source= OrganisationType.CompaniesHouse } , | ||
Agreements = new List<EmployerAgreement>() | ||
{ new EmployerAgreement | ||
{ | ||
SignedDate = DateTime.UtcNow, | ||
} | ||
|
||
} }); | ||
|
||
_mockhashingService = new Mock<IHashingService>(); | ||
_mockhashingService.Setup(m => m.HashValue(It.IsAny<long>())).Returns(hashedId); | ||
|
||
_mockreferenceDataService = new Mock<IReferenceDataService>(); | ||
_mockreferenceDataService.Setup(m => m.IsIdentifiableOrganisationType(It.IsAny<OrganisationType>())).ReturnsAsync(true); | ||
|
||
var agreements = new List<EmployerAgreementDto> { | ||
new EmployerAgreementDto { Id =1, SignedDate = DateTime.UtcNow , AccountLegalEntity = new AccountLegalEntity { Id = _accountLegelEntityId} }, | ||
new EmployerAgreementDto { Id =2, SignedDate = DateTime.UtcNow , AccountLegalEntity = new AccountLegalEntity { Id = _accountLegelEntityId} }}; | ||
|
||
_mockmapper = new Mock<IMapper>(); | ||
_mockmapper.Setup(m => m.Map<ICollection<EmployerAgreement>, ICollection<EmployerAgreementDto>>(It.IsAny<ICollection<EmployerAgreement>>(), | ||
It.IsAny<Action<IMappingOperationOptions<ICollection<EmployerAgreement>, ICollection<EmployerAgreementDto>>>>())) | ||
.Returns(agreements); | ||
|
||
RequestHandler = new GetOrganisationAgreementsQueryHandler(RequestValidator.Object, _mockEmployerAgreementRepository.Object, _mockAccountLegalEntityPublicHashingService.Object, | ||
_mockhashingService.Object, _mockreferenceDataService.Object, _mockmapper.Object); | ||
|
||
Query = new GetOrganisationAgreementsRequest | ||
{ | ||
AccountLegalEntityHashedId = hashedId | ||
}; | ||
} | ||
|
||
|
||
[Test] | ||
public override async Task ThenIfTheMessageIsValidTheRepositoryIsCalled() | ||
{ | ||
//Act | ||
await RequestHandler.Handle(Query); | ||
|
||
//Assert | ||
_mockEmployerAgreementRepository.Verify(x => x.GetOrganisationAgreement(It.IsAny<long>()), Times.Once); | ||
} | ||
|
||
[Test] | ||
public override async Task ThenIfTheMessageIsValidTheValueIsReturnedInTheResponse() | ||
{ | ||
//Act | ||
var response = await RequestHandler.Handle(Query); | ||
|
||
//Assert | ||
Assert.IsNotNull(response.Agreements); | ||
Assert.IsTrue(response.Agreements.Any()); | ||
} | ||
|
||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...S.EmployerAccounts.UnitTests/Queries/GetOrganisationAgreements/WhenIValidateTheRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using NUnit.Framework; | ||
using SFA.DAS.EmployerAccounts.Queries.GetOrganisationAgreements; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerAccounts.UnitTests.Queries.GetOrganisationAgreements | ||
{ | ||
public class WhenIValidateTheRequest | ||
{ | ||
private GetOrganisationAgreementsValidator _validator; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_validator = new GetOrganisationAgreementsValidator(); | ||
} | ||
|
||
[Test] | ||
public async Task ThenShouldReturnValidIfRequestIsValid() | ||
{ | ||
//Act | ||
var result = await _validator.ValidateAsync(new GetOrganisationAgreementsRequest { AccountLegalEntityHashedId = "Abc123" }); | ||
|
||
//Assert | ||
Assert.IsTrue(result.IsValid()); | ||
} | ||
|
||
[Test] | ||
public async Task ThenShouldReturnInValidIfRequestIsNotValid() | ||
{ | ||
//Act | ||
var result = await _validator.ValidateAsync(new GetOrganisationAgreementsRequest { AccountLegalEntityHashedId = string.Empty }); | ||
|
||
//Assert | ||
Assert.IsFalse(result.IsValid()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
src/SFA.DAS.EmployerAccounts.Web/ViewModels/OrganisationAgreementViewModel.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.