Skip to content

Commit

Permalink
Merge in master
Browse files Browse the repository at this point in the history
  • Loading branch information
ben1stone-leftdfe committed Oct 28, 2020
2 parents 1219fcb + 2f8c7db commit 944fe7b
Show file tree
Hide file tree
Showing 40 changed files with 1,456 additions and 16 deletions.
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;
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Loading

0 comments on commit 944fe7b

Please sign in to comment.