-
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.
- Loading branch information
Showing
40 changed files
with
1,456 additions
and
16 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ntsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/ApprenticeControllerTestBase.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,22 @@ | ||
using Moq; | ||
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; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class ApprenticeControllerTestBase | ||
{ | ||
protected const string _apprenticeshipDetailsUrl = "https://commitments.apprenticeships.gov.uk/accounts/apprentices/ABC123/details"; | ||
protected const string _apprenticeshipStopUrl = "https://commitments.apprenticeships.gov.uk/accounts/apprentices/ABC123/stop/whentoapply"; | ||
|
||
protected Mock<IModelMapper> _mockModelMapper; | ||
protected Mock<ICookieStorageService<IndexRequest>> _mockCookieStorageService; | ||
protected Mock<ICommitmentsApiClient> _mockCommitmentsApiClient; | ||
protected Mock<ILinkGenerator> _mockLinkGenerator; | ||
|
||
protected ApprenticeController _controller; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...mitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingChangeStatus.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,62 @@ | ||
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; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class WhenPostingChangeStatus : ApprenticeControllerTestBase | ||
{ | ||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockModelMapper = new Mock<IModelMapper>(); | ||
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>(); | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
|
||
_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public void AndPauseIsSelected_ThenRedirectToPauseApprenticeshipAction(ChangeStatusRequestViewModel viewModel) | ||
{ | ||
viewModel.SelectedStatusChange = ChangeStatusType.Pause; | ||
|
||
var response = _controller.ChangeStatus(viewModel) as RedirectToActionResult; | ||
|
||
Assert.AreEqual("PauseApprenticeship", response.ActionName); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public void AndGoBackIsSelected_ThenRedirectToPauseApprenticeshipAction(ChangeStatusRequestViewModel viewModel) | ||
{ | ||
viewModel.SelectedStatusChange = ChangeStatusType.GoBack; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{viewModel.AccountHashedId}/apprentices/manage/{viewModel.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var response = _controller.ChangeStatus(viewModel) as RedirectResult; | ||
|
||
Assert.AreEqual(_apprenticeshipDetailsUrl, response.Url); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public void AndStopIsSelected_ThenRedirectToV1WhenToApplyStopAction(ChangeStatusRequestViewModel viewModel) | ||
{ | ||
viewModel.SelectedStatusChange = ChangeStatusType.Stop; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{viewModel.AccountHashedId}/apprentices/manage/{viewModel.ApprenticeshipHashedId}/details/statuschange/stop/whentoapply")) | ||
.Returns(_apprenticeshipStopUrl); | ||
|
||
var response = _controller.ChangeStatus(viewModel) as RedirectResult; | ||
|
||
Assert.AreEqual(_apprenticeshipStopUrl, response.Url); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...eb.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingPauseRequestConfirmation.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,80 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Requests; | ||
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; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
[TestFixture] | ||
public class WhenPostingPauseRequestConfirmation : ApprenticeControllerTestBase | ||
{ | ||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockModelMapper = new Mock<IModelMapper>(); | ||
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>(); | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
|
||
_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndConfirmPauseIsSelected_ThenCommitmentsApiPauseApprenticeshipIsCalled(PauseRequestViewModel request) | ||
{ | ||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var result = await _controller.PauseApprenticeship(request); | ||
|
||
_mockCommitmentsApiClient.Verify(p => p.PauseApprenticeship(It.IsAny<PauseApprenticeshipRequest>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndConfirmPauseIsSelected_ThenRedirectToApprenticeDetailsPage(PauseRequestViewModel request) | ||
{ | ||
request.PauseConfirmed = true; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var result = await _controller.PauseApprenticeship(request) as RedirectResult; | ||
|
||
Assert.AreEqual(_apprenticeshipDetailsUrl, result.Url); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndGoBackIsSelected_ThenCommitmentsApiPauseApprenticeshipIsNotCalled(PauseRequestViewModel request) | ||
{ | ||
request.PauseConfirmed = false; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var result = await _controller.PauseApprenticeship(request); | ||
|
||
_mockCommitmentsApiClient.Verify(p => p.PauseApprenticeship(It.IsAny<PauseApprenticeshipRequest>(), It.IsAny<CancellationToken>()), Times.Never); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndGoBackIsSelected_ThenRedirectToApprenticeDetailsPage(PauseRequestViewModel request) | ||
{ | ||
request.PauseConfirmed = false; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var result = await _controller.PauseApprenticeship(request) as RedirectResult; | ||
|
||
Assert.AreEqual(_apprenticeshipDetailsUrl, result.Url); | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...b.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingResumeRequestConfirmation.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,81 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Requests; | ||
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; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
[TestFixture] | ||
public class WhenPostingResumeRequestConfirmation : ApprenticeControllerTestBase | ||
{ | ||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockModelMapper = new Mock<IModelMapper>(); | ||
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>(); | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
|
||
_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndConfirmResumeIsSelected_ThenCommitmentsApiResumeApprenticeshipIsCalled(ResumeRequestViewModel request) | ||
{ | ||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
await _controller.ResumeApprenticeship(request); | ||
|
||
_mockCommitmentsApiClient.Verify(p => | ||
p.ResumeApprenticeship(It.IsAny<ResumeApprenticeshipRequest>(), It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndConfirmResumeIsSelected_ThenRedirectToApprenticeDetailsPage(ResumeRequestViewModel request) | ||
{ | ||
request.ResumeConfirmed = true; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var result = await _controller.ResumeApprenticeship(request) as RedirectResult; | ||
|
||
Assert.AreEqual(_apprenticeshipDetailsUrl, result.Url); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndGoBackIsSelected_ThenCommitmentsApiResumeApprenticeshipIsNotCalled(ResumeRequestViewModel request) | ||
{ | ||
request.ResumeConfirmed = false; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
await _controller.ResumeApprenticeship(request); | ||
|
||
_mockCommitmentsApiClient.Verify(p => p.ResumeApprenticeship(It.IsAny<ResumeApprenticeshipRequest>(), It.IsAny<CancellationToken>()), Times.Never); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndGoBackIsSelected_ThenRedirectToApprenticeDetailsPage(ResumeRequestViewModel request) | ||
{ | ||
request.ResumeConfirmed = false; | ||
|
||
_mockLinkGenerator.Setup(p => p.CommitmentsLink($"accounts/{request.AccountHashedId}/apprentices/manage/{request.ApprenticeshipHashedId}/details")) | ||
.Returns(_apprenticeshipDetailsUrl); | ||
|
||
var result = await _controller.ResumeApprenticeship(request) as RedirectResult; | ||
|
||
Assert.AreEqual(_apprenticeshipDetailsUrl, result.Url); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...sV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingChangeStatusPage.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,38 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.CommitmentsV2.Types; | ||
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 WhenRequestingChangeStatusPage : ApprenticeControllerTestBase | ||
{ | ||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockModelMapper = new Mock<IModelMapper>(); | ||
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>(); | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
|
||
_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object); | ||
} | ||
|
||
[Test] | ||
public async Task AndCurrentStatusIsLive_ThenViewIsReturned() | ||
{ | ||
_mockModelMapper.Setup(m => m.Map<ChangeStatusRequestViewModel>(It.IsAny<ChangeStatusRequest>())) | ||
.ReturnsAsync(new ChangeStatusRequestViewModel { CurrentStatus = ApprenticeshipStatus.Live }); | ||
|
||
var result = await _controller.ChangeStatus(new ChangeStatusRequest()); | ||
|
||
Assert.IsInstanceOf<ViewResult>(result); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ontrollers/ApprenticeControllerTests/WhenRequestingPauseApprenticeshipConfirmationPage.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,53 @@ | ||
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 WhenRequestingPauseApprenticeshipConfirmationPage : ApprenticeControllerTestBase | ||
{ | ||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockModelMapper = new Mock<IModelMapper>(); | ||
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>(); | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
|
||
_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object); | ||
} | ||
|
||
[Test] | ||
public async Task AndCurrentStatusIsLive_ThenViewIsReturned() | ||
{ | ||
_mockModelMapper.Setup(m => m.Map<PauseRequestViewModel>(It.IsAny<PauseRequest>())) | ||
.ReturnsAsync(new PauseRequestViewModel()); | ||
|
||
var result = await _controller.PauseApprenticeship(new PauseRequest()); | ||
|
||
Assert.IsInstanceOf<ViewResult>(result); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task AndCurrentStatusIsLive_ThenPauseRequestViewModelIsPassedToTheView(PauseRequestViewModel _viewModel) | ||
{ | ||
_mockModelMapper.Setup(m => m.Map<PauseRequestViewModel>(It.IsAny<PauseRequest>())) | ||
.ReturnsAsync(_viewModel); | ||
|
||
var viewResult = await _controller.PauseApprenticeship(new PauseRequest()) as ViewResult; | ||
var viewModel = viewResult.Model; | ||
|
||
var pauseRequestViewModel = (PauseRequestViewModel)viewModel; | ||
|
||
Assert.IsInstanceOf<PauseRequestViewModel>(viewModel); | ||
Assert.AreEqual(_viewModel, pauseRequestViewModel); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ntrollers/ApprenticeControllerTests/WhenRequestingResumeApprenticeshipConfirmationPage.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,45 @@ | ||
using System; | ||
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 WhenRequestingResumeApprenticeshipConfirmationPage : ApprenticeControllerTestBase | ||
{ | ||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_mockModelMapper = new Mock<IModelMapper>(); | ||
_mockCookieStorageService = new Mock<ICookieStorageService<IndexRequest>>(); | ||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockLinkGenerator = new Mock<ILinkGenerator>(); | ||
|
||
_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object); | ||
} | ||
|
||
[Test] | ||
public async Task AndCurrentStatusIsPaused_ThenViewIsReturned() | ||
{ | ||
DateTime resumedDate = DateTime.Now; | ||
_mockModelMapper.Setup(m => m.Map<ResumeRequestViewModel>(It.IsAny<ResumeRequest>())) | ||
.ReturnsAsync(new ResumeRequestViewModel() | ||
{ | ||
ResumeDate = resumedDate | ||
}); | ||
|
||
var result = await _controller.ResumeApprenticeship(new ResumeRequest()); | ||
|
||
var viewResult = (ViewResult)result; | ||
var viewModel = viewResult.Model; | ||
Assert.That(viewModel, Is.TypeOf<ResumeRequestViewModel>()); | ||
Assert.IsInstanceOf<ViewResult>(result); | ||
} | ||
} | ||
} |
Oops, something went wrong.