-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from SkillsFundingAgency/CON-2507-Show-employ…
…er-a-request-submitted-confirmation Con 2507 show employer a request submitted confirmation
- Loading branch information
Showing
13 changed files
with
375 additions
and
42 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...lers/ApprenticeControllerTests/WhenCallingChangeProviderRequestedConfirmationPageTests.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,76 @@ | ||
using AutoFixture; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.EmployerUrlHelper; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class WhenCallingChangeProviderRequestedConfirmationPageTests | ||
{ | ||
private WhenCallingChangeProviderRequestedConfirmationPageTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new WhenCallingChangeProviderRequestedConfirmationPageTestsFixture(); | ||
|
||
} | ||
|
||
[Test] | ||
public async Task ThenViewIsReturned() | ||
{ | ||
var result = await _fixture.ChangeProviderRequested(); | ||
|
||
_fixture.VerifyViewModel(result); | ||
} | ||
} | ||
|
||
public class WhenCallingChangeProviderRequestedConfirmationPageTestsFixture | ||
{ | ||
private readonly ChangeProviderRequestedConfirmationRequest _request; | ||
private readonly ChangeProviderRequestedConfirmationViewModel _viewModel; | ||
|
||
private Mock<IModelMapper> _mockMapper; | ||
|
||
private ApprenticeController _controller; | ||
|
||
public WhenCallingChangeProviderRequestedConfirmationPageTestsFixture() | ||
{ | ||
var autoFixture = new Fixture(); | ||
_request = autoFixture.Create<ChangeProviderRequestedConfirmationRequest>(); | ||
_viewModel = autoFixture.Create<ChangeProviderRequestedConfirmationViewModel>(); | ||
|
||
_mockMapper = new Mock<IModelMapper>(); | ||
_mockMapper.Setup(m => m.Map<ChangeProviderRequestedConfirmationViewModel>(_request)) | ||
.ReturnsAsync(_viewModel); | ||
|
||
_controller = new ApprenticeController(_mockMapper.Object, | ||
Mock.Of<ICookieStorageService<IndexRequest>>(), | ||
Mock.Of<ICommitmentsApiClient>(), | ||
Mock.Of<ILinkGenerator>()); | ||
} | ||
|
||
public async Task<IActionResult> ChangeProviderRequested() | ||
{ | ||
return await _controller.ChangeProviderRequested(_request); | ||
} | ||
|
||
public void VerifyViewModel(IActionResult actionResult) | ||
{ | ||
var result = actionResult as ViewResult; | ||
var viewModel = result.Model; | ||
|
||
Assert.IsInstanceOf<ChangeProviderRequestedConfirmationViewModel>(viewModel); | ||
|
||
var changeProviderRequestedViewModel = viewModel as ChangeProviderRequestedConfirmationViewModel; | ||
|
||
Assert.AreEqual(_viewModel, changeProviderRequestedViewModel); | ||
} | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
...b.UnitTests/Mappers/Apprentice/ChangeProviderRequestedConfirmationViewModelMapperTests.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,87 @@ | ||
using AutoFixture; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.Testing.AutoFixture; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice | ||
{ | ||
public class ChangeProviderRequestedConfirmationViewModelMapperTests | ||
{ | ||
|
||
private Mock<ICommitmentsApiClient> _mockCommitmentsApi; | ||
private GetApprenticeshipResponse _apprenticeshipResponse; | ||
private GetProviderResponse _providerResponse; | ||
|
||
private ChangeProviderRequestedConfirmationViewModelMapper _mapper; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
var autoFixture = new Fixture(); | ||
|
||
_apprenticeshipResponse = autoFixture.Build<GetApprenticeshipResponse>() | ||
.With(a => a.FirstName, "FirstName") | ||
.With(a => a.LastName, "LastName") | ||
.Create(); | ||
|
||
_providerResponse = autoFixture.Build<GetProviderResponse>() | ||
.With(p => p.Name, "Test Provider") | ||
.Create(); | ||
|
||
_mockCommitmentsApi = new Mock<ICommitmentsApiClient>(); | ||
|
||
_mockCommitmentsApi.Setup(c => c.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_apprenticeshipResponse); | ||
_mockCommitmentsApi.Setup(c => c.GetProvider(It.IsAny<long>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_providerResponse); | ||
|
||
_mapper = new ChangeProviderRequestedConfirmationViewModelMapper(_mockCommitmentsApi.Object); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task ApprenticeshipHashedId_IsMapped(ChangeProviderRequestedConfirmationRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual(request.ApprenticeshipHashedId, result.ApprenticeshipHashedId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AccountHashedId_IsMapped(ChangeProviderRequestedConfirmationRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual(request.AccountHashedId, result.AccountHashedId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task GetApprenticeshipIsCalled(ChangeProviderRequestedConfirmationRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
_mockCommitmentsApi.Verify(c => c.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task ApprenticeName_IsMapped(ChangeProviderRequestedConfirmationRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual($"{_apprenticeshipResponse.FirstName} {_apprenticeshipResponse.LastName}", result.ApprenticeName); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task ProviderName_IsMapped(ChangeProviderRequestedConfirmationRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual(_providerResponse.Name, result.ProviderName); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...mmitmentsV2.Web.UnitTests/Validators/ChangeProviderRequestedConfirmationValidatorTests.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,68 @@ | ||
using FluentValidation.TestHelper; | ||
using NUnit.Framework; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Validators; | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Validators | ||
{ | ||
[TestFixture] | ||
public class ChangeProviderRequestedConfirmationValidatorTests | ||
{ | ||
[TestCase(1, true)] | ||
[TestCase(default(long), false)] | ||
public void ThenValidatesProviderId(long providerId, bool expectedValid) | ||
{ | ||
var request = new ChangeProviderRequestedConfirmationRequest { ProviderId = providerId}; | ||
|
||
AssertValidationResult(x => x.ProviderId, request, expectedValid); | ||
} | ||
|
||
[TestCase(1, true)] | ||
[TestCase(default(long), false)] | ||
public void ThenValidatesApprenticeshipId(long apprenticeshipId, bool expectedValid) | ||
{ | ||
var request = new ChangeProviderRequestedConfirmationRequest { ApprenticeshipId = apprenticeshipId}; | ||
|
||
AssertValidationResult(x => x.ApprenticeshipId, request, expectedValid); | ||
} | ||
|
||
[TestCase("", false)] | ||
[TestCase(" ", false)] | ||
[TestCase("testString", true)] | ||
[TestCase(null, false)] | ||
public void ThenValidatesAccountHashedId(string accountHashedId, bool expectedValid) | ||
{ | ||
var request = new ChangeProviderRequestedConfirmationRequest { AccountHashedId = accountHashedId }; | ||
|
||
AssertValidationResult(x => x.AccountHashedId, request, expectedValid); | ||
} | ||
|
||
[TestCase("", false)] | ||
[TestCase(" ", false)] | ||
[TestCase("testString", true)] | ||
[TestCase(null, false)] | ||
public void ThenValidatesApprenticeshipHashedId(string apprenticeshipHashedId, bool expectedValid) | ||
{ | ||
var request = new ChangeProviderRequestedConfirmationRequest { ApprenticeshipHashedId = apprenticeshipHashedId }; | ||
|
||
AssertValidationResult(x => x.ApprenticeshipHashedId, request, expectedValid); | ||
} | ||
|
||
|
||
private void AssertValidationResult<T>(Expression<Func<ChangeProviderRequestedConfirmationRequest, T>> property, ChangeProviderRequestedConfirmationRequest instance, bool expectedValid) | ||
{ | ||
var validator = new ChangeProviderRequestedConfirmationValidator(); | ||
|
||
if (expectedValid) | ||
{ | ||
validator.ShouldNotHaveValidationErrorFor(property, instance); | ||
} | ||
else | ||
{ | ||
validator.ShouldHaveValidationErrorFor(property, instance); | ||
} | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...ommitmentsV2.Web/Mappers/Apprentice/ChangeProviderRequestedConfirmationViewModelMapper.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,35 @@ | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice | ||
{ | ||
public class ChangeProviderRequestedConfirmationViewModelMapper : IMapper<ChangeProviderRequestedConfirmationRequest, ChangeProviderRequestedConfirmationViewModel> | ||
{ | ||
private readonly ICommitmentsApiClient _client; | ||
|
||
public ChangeProviderRequestedConfirmationViewModelMapper(ICommitmentsApiClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
public async Task<ChangeProviderRequestedConfirmationViewModel> Map(ChangeProviderRequestedConfirmationRequest source) | ||
{ | ||
var getProviderTask = _client.GetProvider(source.ProviderId); | ||
var getApprenticeshipTask = _client.GetApprenticeship(source.ApprenticeshipId); | ||
|
||
await Task.WhenAll(getProviderTask, getApprenticeshipTask); | ||
|
||
var result = new ChangeProviderRequestedConfirmationViewModel | ||
{ | ||
ApprenticeshipHashedId = source.ApprenticeshipHashedId, | ||
AccountHashedId = source.AccountHashedId, | ||
ProviderName = getProviderTask.Result.Name, | ||
ApprenticeName = $"{getApprenticeshipTask.Result.FirstName} {getApprenticeshipTask.Result.LastName}" | ||
}; | ||
|
||
return result; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.