-
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 #146 from SkillsFundingAgency/CON-2505-CoP-Enter-t…
…he-new-training-provider CON-2505 CoP enter the new training provider
- Loading branch information
Showing
22 changed files
with
609 additions
and
20 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...ests/Controllers/ApprenticeControllerTests/WhenCallingGetEnterNewTrainingProviderTests.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,78 @@ | ||
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; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class WhenCallingGetEnterNewTrainingProviderTests | ||
{ | ||
WhenCallingGetEnterNewTrainingProviderTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new WhenCallingGetEnterNewTrainingProviderTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task ThenViewIsReturned() | ||
{ | ||
var result = await _fixture.EnterNewTrainingProvider(); | ||
|
||
_fixture.VerifyViewModel(result); | ||
} | ||
} | ||
|
||
public class WhenCallingGetEnterNewTrainingProviderTestsFixture | ||
{ | ||
private readonly Mock<IModelMapper> _mockMapper; | ||
|
||
private EnterNewTrainingProviderRequest _request; | ||
private EnterNewTrainingProviderViewModel _viewModel; | ||
|
||
private ApprenticeController _controller; | ||
|
||
public WhenCallingGetEnterNewTrainingProviderTestsFixture() | ||
{ | ||
var autoFixture = new Fixture(); | ||
_request = autoFixture.Create<EnterNewTrainingProviderRequest>(); | ||
_viewModel = autoFixture.Create<EnterNewTrainingProviderViewModel>(); | ||
|
||
_mockMapper = new Mock<IModelMapper>(); | ||
_mockMapper.Setup(m => m.Map<EnterNewTrainingProviderViewModel>(_request)) | ||
.ReturnsAsync(_viewModel); | ||
|
||
_controller = new ApprenticeController(_mockMapper.Object, | ||
Mock.Of<ICookieStorageService<IndexRequest>>(), | ||
Mock.Of<ICommitmentsApiClient>(), | ||
Mock.Of<ILinkGenerator>()); | ||
} | ||
|
||
public async Task<IActionResult> EnterNewTrainingProvider() | ||
{ | ||
return await _controller.EnterNewTrainingProvider(_request); | ||
} | ||
|
||
public void VerifyViewModel(IActionResult actionResult) | ||
{ | ||
var result = actionResult as ViewResult; | ||
var viewModel = result.Model; | ||
|
||
Assert.IsInstanceOf<EnterNewTrainingProviderViewModel>(viewModel); | ||
|
||
var enterNewTrainingProviderViewModel = (EnterNewTrainingProviderViewModel)viewModel; | ||
|
||
Assert.AreEqual(_viewModel, enterNewTrainingProviderViewModel); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...eb.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingEnterNewTrainingProvider.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,75 @@ | ||
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; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class WhenPostingEnterNewTrainingProvider | ||
{ | ||
private WhenPostingEnterNewTrainingProviderFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new WhenPostingEnterNewTrainingProviderFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task ThenRedirectToSendRequestPage() | ||
{ | ||
var result = await _fixture.EnterNewTrainingProvider(); | ||
|
||
_fixture.VerifyRedirectsToSendNewTrainingProviderRequest(result); | ||
} | ||
} | ||
|
||
public class WhenPostingEnterNewTrainingProviderFixture | ||
{ | ||
private readonly Mock<IModelMapper> _mockMapper; | ||
private readonly Mock<ILinkGenerator> _mockLinkGenerator; | ||
private readonly EnterNewTrainingProviderViewModel _viewModel; | ||
|
||
private readonly ApprenticeController _controller; | ||
|
||
public WhenPostingEnterNewTrainingProviderFixture() | ||
{ | ||
var autoFixture = new Fixture(); | ||
|
||
_viewModel = autoFixture.Create<EnterNewTrainingProviderViewModel>(); | ||
|
||
_mockMapper = new Mock<IModelMapper>(); | ||
_mockMapper.Setup(m => m.Map<SendNewTrainingProviderRequest>(_viewModel)) | ||
.ReturnsAsync(new SendNewTrainingProviderRequest { AccountHashedId = _viewModel.AccountHashedId, ApprenticeshipHashedId = _viewModel.ApprenticeshipHashedId, Ukprn = _viewModel.Ukprn }); | ||
|
||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
_mockLinkGenerator.Setup(x => x.CommitmentsLink(It.IsAny<string>())).Returns<string>(s => s); | ||
|
||
_controller = new ApprenticeController(_mockMapper.Object, Mock.Of<ICookieStorageService<IndexRequest>>(), Mock.Of<ICommitmentsApiClient>(), _mockLinkGenerator.Object); | ||
|
||
} | ||
|
||
public async Task<IActionResult> EnterNewTrainingProvider() | ||
{ | ||
return await _controller.EnterNewTrainingProvider(_viewModel); | ||
} | ||
|
||
public void VerifyRedirectsToSendNewTrainingProviderRequest(IActionResult result) | ||
{ | ||
var redirect = (RedirectToRouteResult)result; | ||
|
||
Assert.AreEqual(RouteNames.SendRequestNewTrainingProvider, redirect.RouteName); | ||
} | ||
|
||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...tmentsV2.Web.UnitTests/Mappers/Apprentice/EnterNewTrainingProviderViewModelMapperTests.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,75 @@ | ||
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.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice | ||
{ | ||
public class EnterNewTrainingProviderViewModelMapperTests | ||
{ | ||
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient; | ||
|
||
private EnterNewTrainingProviderViewModelMapper _mapper; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
|
||
_mockCommitmentsApiClient.Setup(m => m.GetAllProviders(It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(MockGetAllProvidersResponse()); | ||
|
||
_mapper = new EnterNewTrainingProviderViewModelMapper(_mockCommitmentsApiClient.Object); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task ApprenticeshipHashedId_IsMapped(EnterNewTrainingProviderRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual(request.ApprenticeshipHashedId, result.ApprenticeshipHashedId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AccountHashedId_IsMapped(EnterNewTrainingProviderRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual(request.AccountHashedId, result.AccountHashedId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task WhenRequestingEnterNewTrainingProvider_ThenListOfGetAllProvidersCalled(EnterNewTrainingProviderRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
_mockCommitmentsApiClient.Verify(m => m.GetAllProviders(It.IsAny<CancellationToken>()), Times.Once()); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task WhenRequestingEnterNewTrainingProvider_ThenListOfTrainingProvidersIsMapped(EnterNewTrainingProviderRequest request) | ||
{ | ||
var result = await _mapper.Map(request); | ||
|
||
Assert.AreEqual(3, result.Providers.Count); | ||
} | ||
private GetAllProvidersResponse MockGetAllProvidersResponse() | ||
{ | ||
return new GetAllProvidersResponse | ||
{ | ||
Providers = new List<Provider> | ||
{ | ||
new Provider { Ukprn = 10000001, Name = "Provider 1" }, | ||
new Provider { Ukprn = 10000002, Name = "Provider 2" }, | ||
new Provider { Ukprn = 10000003, Name = "Provider 3" } | ||
} | ||
}; | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...mmitmentsV2.Web.UnitTests/Mappers/Apprentice/SendNewTrainingProviderRequestMapperTests.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,46 @@ | ||
using NUnit.Framework; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.Testing.AutoFixture; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice | ||
{ | ||
public class SendNewTrainingProviderRequestMapperTests | ||
{ | ||
private SendNewTrainingProviderRequestMapper _mapper; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mapper = new SendNewTrainingProviderRequestMapper(); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task ApprenticeshipHashedId_IsMapped(EnterNewTrainingProviderViewModel viewModel) | ||
{ | ||
var result = await _mapper.Map(viewModel); | ||
|
||
Assert.AreEqual(viewModel.ApprenticeshipHashedId, result.ApprenticeshipHashedId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AccountHashedId_IsMapped(EnterNewTrainingProviderViewModel viewModel) | ||
{ | ||
var result = await _mapper.Map(viewModel); | ||
|
||
Assert.AreEqual(viewModel.AccountHashedId, result.AccountHashedId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Ukprn_IsMapped(EnterNewTrainingProviderViewModel viewModel) | ||
{ | ||
var result = await _mapper.Map(viewModel); | ||
|
||
Assert.AreEqual(viewModel.Ukprn, result.Ukprn); | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...CommitmentsV2.Web.UnitTests/Validators/EnterNewTrainingProviderViewModelValidatorTests.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,41 @@ | ||
using NUnit.Framework; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Validators; | ||
using SFA.DAS.Testing.AutoFixture; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Validators | ||
{ | ||
public class EnterNewTrainingProviderViewModelValidatorTests | ||
{ | ||
private const string ExpectedUkprnErrorMessage = "Select a training provider"; | ||
private EnterNewTrainingProviderViewModelValidator _validator; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_validator = new EnterNewTrainingProviderViewModelValidator(); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public void WhenValidatingNewTrainingProvider_AndAnUkprnIsNotGiven_ThenValidatorReturnsInvalid(EnterNewTrainingProviderViewModel viewModel) | ||
{ | ||
viewModel.Ukprn = 0; | ||
var result = _validator.Validate(viewModel); | ||
|
||
Assert.False(result.IsValid); | ||
Assert.AreEqual(ExpectedUkprnErrorMessage, result.Errors.First().ErrorMessage); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public void WhenValidatingNewTrainingProvider_AndAnUkprnIsGiven_ThenValidatorReturnsValid(EnterNewTrainingProviderViewModel viewModel) | ||
{ | ||
var result = _validator.Validate(viewModel); | ||
|
||
Assert.True(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
Oops, something went wrong.