-
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 #100 from SkillsFundingAgency/MF-431-manage-appren…
…tices-table MF-431 manage apprentices table
- Loading branch information
Showing
38 changed files
with
2,493 additions
and
68 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...itmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/DownloadApprenticesTests.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.IO; | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Shared.ActionResults; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
public class DownloadApprenticesTests | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task ThenTheFileContentIsSetCorrectly( | ||
DownloadRequest request, | ||
string expectedFileName, | ||
[Frozen] Mock<IModelMapper> csvMapper, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
var expectedCsvContent = new DownloadViewModel | ||
{ | ||
Name = expectedFileName, | ||
Content = new MemoryStream() | ||
}; | ||
csvMapper.Setup(x => | ||
x.Map<DownloadViewModel>(request)) | ||
.ReturnsAsync(expectedCsvContent); | ||
|
||
//Act | ||
var actual = await controller.Download(request); | ||
|
||
var actualFileResult = actual as FileResult; | ||
|
||
//Assert | ||
Assert.IsNotNull(actualFileResult); | ||
Assert.AreEqual(expectedCsvContent.Name, actualFileResult.FileDownloadName); | ||
Assert.AreEqual(expectedCsvContent.ContentType, actualFileResult.ContentType); | ||
} | ||
} | ||
} |
184 changes: 168 additions & 16 deletions
184
...mmitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/ManageApprenticesTests.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 |
---|---|---|
@@ -1,42 +1,194 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Cookies; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests | ||
{ | ||
[TestFixture] | ||
public class ManageApprenticesTests | ||
{ | ||
private ApprenticeController _controller; | ||
[Test, MoqAutoData] | ||
public async Task ThenTheMappedViewModelIsReturned( | ||
IndexRequest request, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(request)) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
//Act | ||
var result = await controller.Index(request) as ViewResult; | ||
var actualModel = result.Model as IndexViewModel; | ||
|
||
//Assert | ||
actualModel.Should().BeEquivalentTo(expectedViewModel); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_SortedByHeaderClassName_Set( | ||
IndexRequest request, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
expectedViewModel.FilterModel.ReverseSort = false; | ||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(request)) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
//Act | ||
var result = await controller.Index(request) as ViewResult; | ||
var actualModel = result.Model as IndexViewModel; | ||
|
||
//Assert | ||
actualModel.SortedByHeaderClassName.Should().EndWith("das-table__sort--asc"); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Will_Update_Search_Details_To_Cookies( | ||
IndexRequest request, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
[Frozen] Mock<ICookieStorageService<IndexRequest>> cookieService, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
request.FromSearch = false; | ||
|
||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(It.IsAny<IndexRequest>())) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
//Act | ||
await controller.Index(request); | ||
|
||
//Assert | ||
cookieService.Verify(x => x.Update(CookieNames.ManageApprentices, request, It.IsAny<int>())); | ||
cookieService.Verify(x => x.Get(It.IsAny<string>()), Times.Never); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Will_Get_Saved_Search_Details_From_Cookies( | ||
IndexRequest request, | ||
IndexRequest savedRequest, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
[Frozen] Mock<ICookieStorageService<IndexRequest>> cookieService, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
request.FromSearch = true; | ||
|
||
[SetUp] | ||
public void Setup() | ||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(It.IsAny<IndexRequest>())) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
cookieService | ||
.Setup(x => x.Get(CookieNames.ManageApprentices)) | ||
.Returns(savedRequest); | ||
|
||
//Act | ||
await controller.Index(request); | ||
|
||
//Assert | ||
cookieService.Verify(x => x.Get(CookieNames.ManageApprentices)); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Will_Used_Saved_Search_Details_From_Cookies( | ||
IndexRequest request, | ||
IndexRequest savedRequest, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
[Frozen] Mock<ICookieStorageService<IndexRequest>> cookieService, | ||
ApprenticeController controller) | ||
{ | ||
_controller = new ApprenticeController(); | ||
//Arrange | ||
request.FromSearch = true; | ||
|
||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(It.IsAny<IndexRequest>())) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
cookieService | ||
.Setup(x => x.Get(CookieNames.ManageApprentices)) | ||
.Returns(savedRequest); | ||
|
||
//Act | ||
await controller.Index(request); | ||
|
||
//Assert | ||
apprenticeshipMapper.Verify(mapper => mapper.Map<IndexViewModel>(savedRequest)); | ||
} | ||
|
||
[Test] | ||
public void AndIsCalledWithInvalidModelStateThenBadResponseShouldBeReturned() | ||
[Test, MoqAutoData] | ||
public async Task Then_Will_Update_Saved_Search_Details_If_From_Cookies( | ||
IndexRequest request, | ||
IndexRequest savedRequest, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
[Frozen] Mock<ICookieStorageService<IndexRequest>> cookieService, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
_controller.ModelState.AddModelError("test", "test"); | ||
request.FromSearch = true; | ||
|
||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(It.IsAny<IndexRequest>())) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
cookieService | ||
.Setup(x => x.Get(CookieNames.ManageApprentices)) | ||
.Returns(savedRequest); | ||
|
||
//Act | ||
var result = _controller.Index(""); | ||
await controller.Index(request); | ||
|
||
//Assert | ||
Assert.IsInstanceOf<BadRequestObjectResult>(result); | ||
cookieService.Verify(x => x.Update( | ||
CookieNames.ManageApprentices, It.IsAny<IndexRequest>(), It.IsAny<int>()), Times.Never); | ||
} | ||
|
||
[Test] | ||
public void ThenTheAccountHashedIdIsPassedToTheViewModel() | ||
[Test, MoqAutoData] | ||
public async Task Then_Will_Used_Current_Search_Details_If_Saved_Details_Not_Available( | ||
IndexRequest request, | ||
IndexViewModel expectedViewModel, | ||
[Frozen] Mock<IModelMapper> apprenticeshipMapper, | ||
[Frozen] Mock<ICookieStorageService<IndexRequest>> cookieService, | ||
ApprenticeController controller) | ||
{ | ||
//Arrange | ||
var expectedAccountHashedId = "TEST"; | ||
request.FromSearch = true; | ||
|
||
apprenticeshipMapper | ||
.Setup(mapper => mapper.Map<IndexViewModel>(It.IsAny<IndexRequest>())) | ||
.ReturnsAsync(expectedViewModel); | ||
|
||
cookieService | ||
.Setup(x => x.Get(CookieNames.ManageApprentices)) | ||
.Returns((IndexRequest)null); | ||
|
||
//Act | ||
var result = _controller.Index(expectedAccountHashedId); | ||
var view = ((ViewResult) result).Model as ManageApprenticesViewModel; | ||
await controller.Index(request); | ||
|
||
//Assert | ||
Assert.AreEqual(expectedAccountHashedId, view.AccountHashedId); | ||
apprenticeshipMapper.Verify(mapper => mapper.Map<IndexViewModel>(request)); | ||
|
||
cookieService.Verify(x => x.Update( | ||
CookieNames.ManageApprentices, It.IsAny<IndexRequest>(), It.IsAny<int>()), Times.Once); | ||
|
||
} | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
...itmentsV2.Web.UnitTests/Mappers/Apprentice/ApprenticeshipDetailsToViewModelMapperTests.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,105 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
using SFA.DAS.CommitmentsV2.Shared.Extensions; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; | ||
using SFA.DAS.Encoding; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice | ||
{ | ||
public class ApprenticeshipDetailsToViewModelMapperTests | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_Maps_ApprenticeshipId( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
string encodedApprenticeshipId, | ||
[Frozen] Mock<IEncodingService> mockEncodingService, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
mockEncodingService | ||
.Setup(service => service.Encode(source.Id, EncodingType.ApprenticeshipId)) | ||
.Returns(encodedApprenticeshipId); | ||
|
||
var result = await mapper.Map(source); | ||
|
||
result.EncodedApprenticeshipId.Should().Be(encodedApprenticeshipId); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_ApprenticeName( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var result = await mapper.Map(source); | ||
|
||
result.ApprenticeName.Should().Be($"{source.FirstName} {source.LastName}"); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_ProviderName( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var result = await mapper.Map(source); | ||
|
||
result.ProviderName.Should().Be(source.ProviderName); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_CourseName( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var result = await mapper.Map(source); | ||
|
||
result.CourseName.Should().Be(source.CourseName); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_PlannedStartDate( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var result = await mapper.Map(source); | ||
|
||
result.PlannedStartDate.Should().Be(source.StartDate); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_PlannedEndDate( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var result = await mapper.Map(source); | ||
|
||
result.PlannedEndDate.Should().Be(source.EndDate); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_ApprenticeshipStatus( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var result = await mapper.Map(source); | ||
|
||
result.Status.Should().Be(source.ApprenticeshipStatus.GetDescription()); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task Then_Maps_Alerts( | ||
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source, | ||
ApprenticeshipDetailsToViewModelMapper mapper) | ||
{ | ||
var alertStrings = source.Alerts.Select(x => x.GetDescription()); | ||
|
||
var result = await mapper.Map(source); | ||
|
||
result.Alerts.Should().BeEquivalentTo(alertStrings); | ||
} | ||
} | ||
} |
Oops, something went wrong.