-
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 #145 from SkillsFundingAgency/CON-2506-send-reques…
…t-new-training-provider Con 2506 send request new training provider
- Loading branch information
Showing
18 changed files
with
639 additions
and
30 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...ontrollers/ApprenticeControllerTests/WhenCallingGetSendRequestNewTrainingProviderTests.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 AutoFixture.NUnit3; | ||
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 SFA.DAS.Testing.AutoFixture; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class WhenCallingGetSendRequestNewTrainingProviderTests | ||
{ | ||
WhenCallingGetSendRequestNewTrainingProviderTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new WhenCallingGetSendRequestNewTrainingProviderTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task Then_The_View_Is_Returned() | ||
{ | ||
var actionResult = await _fixture.SendRequestNewTrainingProvider(); | ||
|
||
_fixture.VerifyViewModel(actionResult); | ||
} | ||
} | ||
|
||
public class WhenCallingGetSendRequestNewTrainingProviderTestsFixture | ||
{ | ||
private readonly Mock<IModelMapper> _modelMapper; | ||
private ApprenticeController _controller; | ||
private SendNewTrainingProviderViewModel _expectedViewModel; | ||
private SendNewTrainingProviderRequest _request; | ||
|
||
public WhenCallingGetSendRequestNewTrainingProviderTestsFixture() | ||
{ | ||
var autoFixture = new Fixture(); | ||
_expectedViewModel = autoFixture.Create<SendNewTrainingProviderViewModel>(); | ||
_request = autoFixture.Create<SendNewTrainingProviderRequest>(); | ||
|
||
|
||
_modelMapper = new Mock<IModelMapper>(); | ||
_modelMapper | ||
.Setup(mapper => mapper.Map<SendNewTrainingProviderViewModel>(_request)) | ||
.ReturnsAsync(_expectedViewModel); | ||
|
||
_controller = new ApprenticeController(_modelMapper.Object, | ||
Mock.Of<ICookieStorageService<IndexRequest>>(), | ||
Mock.Of<ICommitmentsApiClient>(), | ||
Mock.Of<ILinkGenerator>()); | ||
} | ||
|
||
public async Task<IActionResult> SendRequestNewTrainingProvider() | ||
{ | ||
return await _controller.SendRequestNewTrainingProvider(_request); | ||
} | ||
|
||
public void VerifyViewModel(IActionResult actionResult) | ||
{ | ||
var result = actionResult as ViewResult; | ||
var viewModel = result.Model; | ||
|
||
Assert.IsInstanceOf<SendNewTrainingProviderViewModel>(viewModel); | ||
var sendNewTrainingProviderViewModel = (SendNewTrainingProviderViewModel)viewModel; | ||
|
||
Assert.AreEqual(_expectedViewModel, sendNewTrainingProviderViewModel); | ||
} | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...s/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.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,94 @@ | ||
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.EmployerCommitmentsV2.Web.RouteValues; | ||
using SFA.DAS.EmployerUrlHelper; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class WhenPostingSendRequestNewTrainingProviderTests | ||
{ | ||
private WhenPostingSendRequestNewTrainingProviderTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new WhenPostingSendRequestNewTrainingProviderTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public void VerifyRedirectsToApprenticeDetailsPage() | ||
{ | ||
_fixture.SetConfirm(false); | ||
|
||
var result = _fixture.SendRequestNewTrainingProvider(); | ||
|
||
_fixture.VerifyRedirectsToApprenticeDetailsPage(result); | ||
} | ||
|
||
[Test] | ||
public void VerifyRedirectsToSentAction() | ||
{ | ||
_fixture.SetConfirm(true); | ||
|
||
var result = _fixture.SendRequestNewTrainingProvider(); | ||
|
||
_fixture.VerifyRedirectsToSentAction(result); | ||
} | ||
} | ||
|
||
public class WhenPostingSendRequestNewTrainingProviderTestsFixture | ||
{ | ||
private readonly Mock<IModelMapper> _modelMapper; | ||
private readonly Mock<ICommitmentsApiClient> _commitmentsApiClient; | ||
private readonly Mock<ILinkGenerator> _linkGenerator; | ||
private ApprenticeController _controller; | ||
private SendNewTrainingProviderViewModel _viewModel; | ||
|
||
public WhenPostingSendRequestNewTrainingProviderTestsFixture() | ||
{ | ||
var autoFixture = new Fixture(); | ||
_viewModel = autoFixture.Create<SendNewTrainingProviderViewModel>(); | ||
|
||
_commitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_modelMapper = new Mock<IModelMapper>(); | ||
|
||
_linkGenerator = new Mock<ILinkGenerator>(); | ||
_linkGenerator.Setup(x => x.CommitmentsLink(It.IsAny<string>())).Returns<string>(s => s); | ||
|
||
_controller = new ApprenticeController(Mock.Of<IModelMapper>(), | ||
Mock.Of<ICookieStorageService<IndexRequest>>(), | ||
_commitmentsApiClient.Object, | ||
_linkGenerator.Object); | ||
} | ||
|
||
public IActionResult SendRequestNewTrainingProvider() | ||
{ | ||
return _controller.SendRequestNewTrainingProvider(_viewModel); | ||
} | ||
|
||
public WhenPostingSendRequestNewTrainingProviderTestsFixture SetConfirm(bool confirm) | ||
{ | ||
_viewModel.Confirm = confirm; | ||
return this; | ||
} | ||
|
||
public void VerifyRedirectsToApprenticeDetailsPage(IActionResult result) | ||
{ | ||
var redirect = (RedirectResult)result; | ||
redirect.WithUrl($"accounts/{_viewModel.AccountHashedId}/apprentices/manage/{_viewModel.ApprenticeshipHashedId}/details"); | ||
} | ||
|
||
public void VerifyRedirectsToSentAction(IActionResult result) | ||
{ | ||
var redirect = (RedirectToRouteResult)result; | ||
|
||
Assert.AreEqual(RouteNames.Sent, redirect.RouteName); | ||
} | ||
} | ||
} |
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
109 changes: 109 additions & 0 deletions
109
...itmentsV2.Web.UnitTests/Mappers/Apprentice/SendNewTrainingProviderViewModelMapperTests.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,109 @@ | ||
using AutoFixture; | ||
using Microsoft.Extensions.Logging; | ||
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 System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice | ||
{ | ||
public class SendNewTrainingProviderViewModelMapperTests | ||
{ | ||
private Mock<ICommitmentsApiClient> _commitmentApiClient; | ||
private GetApprenticeshipResponse _apprenticeshipResponse; | ||
private GetProviderResponse _providerResponse; | ||
private SendNewTrainingProviderViewModelMapper _sut; | ||
private SendNewTrainingProviderRequest _request; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
var autoFixture = new Fixture(); | ||
|
||
_apprenticeshipResponse = autoFixture.Build<GetApprenticeshipResponse>() | ||
.Create(); | ||
_providerResponse = autoFixture.Build<GetProviderResponse>() | ||
.Create(); | ||
_request = autoFixture.Build<SendNewTrainingProviderRequest>() | ||
.Create(); | ||
|
||
|
||
_commitmentApiClient = new Mock<ICommitmentsApiClient>(); | ||
_commitmentApiClient.Setup(a => a.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_apprenticeshipResponse); | ||
|
||
_commitmentApiClient.Setup(a => a.GetProvider(It.IsAny<long>(), It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_providerResponse); | ||
|
||
_sut = new SendNewTrainingProviderViewModelMapper(_commitmentApiClient.Object, Mock.Of<ILogger<SendNewTrainingProviderViewModelMapper>>()); | ||
} | ||
|
||
[Test] | ||
public async Task ApprenticeshipHashedId_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_request.ApprenticeshipHashedId, result.ApprenticeshipHashedId); | ||
} | ||
|
||
[Test] | ||
public async Task AccountHashedId_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_request.AccountHashedId, result.AccountHashedId); | ||
} | ||
|
||
[Test] | ||
public async Task EmployerName_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_apprenticeshipResponse.EmployerName, result.EmployerName); | ||
} | ||
|
||
[Test] | ||
public async Task ApprenticeName_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual($"{_apprenticeshipResponse.FirstName} {_apprenticeshipResponse.LastName}", result.ApprenticeName); | ||
} | ||
|
||
[Test] | ||
public async Task OldProviderName_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_apprenticeshipResponse.ProviderName, result.OldProviderName); | ||
} | ||
|
||
[Test] | ||
public async Task NewProviderName_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_providerResponse.Name, result.NewProviderName); | ||
} | ||
|
||
[Test] | ||
public async Task ProviderId_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_request.ProviderId, result.ProviderId); | ||
} | ||
|
||
[Test] | ||
public async Task ApprenticeshipStatus_IsMapped() | ||
{ | ||
var result = await _sut.Map(_request); | ||
|
||
Assert.AreEqual(_apprenticeshipResponse.Status, result.ApprenticeshipStatus); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...yerCommitmentsV2.Web.UnitTests/Validators/SendNewTrainingProviderRequestValidatorTests.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,73 @@ | ||
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 SendNewTrainingProviderRequestValidatorTests | ||
{ | ||
[TestCase("5143541", true)] | ||
[TestCase(" ", false)] | ||
[TestCase("", false)] | ||
[TestCase(null, false)] | ||
public void ThenAccountHashedIdIsValidated(string accountHashedId, bool expectedValid) | ||
{ | ||
var request = new SendNewTrainingProviderRequest() { AccountHashedId = accountHashedId }; | ||
AssertValidationResult(x => x.AccountHashedId, request, expectedValid); | ||
} | ||
[TestCase("", false)] | ||
[TestCase("31", true)] | ||
[TestCase(" ", false)] | ||
[TestCase(null, false)] | ||
public void ThenApprenticeshipHashedIdIsValidated(string apprenticeshipHashedId, bool expectedValid) | ||
{ | ||
var request = new SendNewTrainingProviderRequest() { ApprenticeshipHashedId = apprenticeshipHashedId }; | ||
AssertValidationResult(x => x.ApprenticeshipHashedId, request, expectedValid); | ||
} | ||
|
||
[TestCase(default(long), false)] | ||
[TestCase(-2342, false)] | ||
[TestCase(234, true)] | ||
public void ThenProviderIsValidated(long providerId, bool expectedValid) | ||
{ | ||
var request = new SendNewTrainingProviderRequest() { ProviderId = providerId }; | ||
AssertValidationResult(x => x.ProviderId, request, expectedValid); | ||
} | ||
|
||
[TestCase(default(long), false)] | ||
[TestCase(-2342, false)] | ||
[TestCase(234, true)] | ||
public void ThenApprenticeshipIdIsValidated(long apprenticeshipId, bool expectedValid) | ||
{ | ||
var request = new SendNewTrainingProviderRequest() { ApprenticeshipId = apprenticeshipId }; | ||
AssertValidationResult(x => x.ApprenticeshipId, request, expectedValid); | ||
} | ||
|
||
[TestCase(default(long), false)] | ||
[TestCase(-2342, false)] | ||
[TestCase(234, true)] | ||
public void ThenAccountIdIsValidated(long accountId, bool expectedValid) | ||
{ | ||
var request = new SendNewTrainingProviderRequest() { AccountId = accountId }; | ||
AssertValidationResult(x => x.AccountId, request, expectedValid); | ||
} | ||
|
||
private void AssertValidationResult<T>(Expression<Func<SendNewTrainingProviderRequest, T>> property, SendNewTrainingProviderRequest instance, bool expectedValid) | ||
{ | ||
var validator = new SendNewTrainingProviderRequestValidator(); | ||
|
||
if (expectedValid) | ||
{ | ||
validator.ShouldNotHaveValidationErrorFor(property, instance); | ||
} | ||
else | ||
{ | ||
validator.ShouldHaveValidationErrorFor(property, instance); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.