generated from SkillsFundingAgency/das-github-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSP-662 Implemented View,Controller,TC
- Loading branch information
1 parent
d0041cb
commit 1475b77
Showing
10 changed files
with
381 additions
and
3 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...rs/Onboarding/CheckYourAnswersControllerTests/CheckYourAnswersControllerAttributeTests.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,18 @@ | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using SFA.DAS.Employer.Aan.Web.Controllers.Onboarding; | ||
using SFA.DAS.Employer.Aan.Web.Infrastructure; | ||
|
||
namespace SFA.DAS.Employer.Aan.Web.UnitTests.Controllers.Onboarding.CheckYourAnswersControllerTests; | ||
|
||
[TestFixture] | ||
public class CheckYourAnswersControllerAttributeTests | ||
{ | ||
[Test] | ||
public void Controller_HasCorrectRouteAttribute() | ||
{ | ||
typeof(CheckYourAnswersController).Should().BeDecoratedWith<RouteAttribute>(); | ||
typeof(CheckYourAnswersController).Should().BeDecoratedWith<RouteAttribute>().Subject.Template.Should().Be("onboarding/check-your-answers"); | ||
typeof(CheckYourAnswersController).Should().BeDecoratedWith<RouteAttribute>().Subject.Name.Should().Be(RouteNames.Onboarding.CheckYourAnswers); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...oarding/CheckYourAnswersControllerTests/WhenGetIsInvoked/AndSessionModelIsNotPopulated.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,54 @@ | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using SFA.DAS.Employer.Aan.Domain.Interfaces; | ||
using SFA.DAS.Employer.Aan.Web.Controllers.Onboarding; | ||
using SFA.DAS.Employer.Aan.Web.Models.Onboarding; | ||
using SFA.DAS.Employer.Aan.Web.UnitTests.TestHelpers; | ||
|
||
namespace SFA.DAS.Employer.Aan.Web.UnitTests.Controllers.Onboarding.CheckYourAnswersControllerTests.WhenGetIsInvoked; | ||
|
||
public class AndSessionModelIsNotPopulated | ||
{ | ||
ViewResult getResult; | ||
CheckYourAnswersViewModel viewModel; | ||
CheckYourAnswersController sut; | ||
OnboardingSessionModel sessionModel; | ||
|
||
[SetUp] | ||
public void Init() | ||
{ | ||
sessionModel = new(); | ||
Mock<ISessionService> sessionServiceMock = new(); | ||
sessionServiceMock.Setup(s => s.Get<OnboardingSessionModel>()).Returns(sessionModel); | ||
sut = new(sessionServiceMock.Object); | ||
|
||
sut.AddUrlHelperMock(); | ||
|
||
sessionModel.Regions = new(); | ||
|
||
getResult = sut.Get().As<ViewResult>(); | ||
viewModel = getResult.Model.As<CheckYourAnswersViewModel>(); | ||
} | ||
|
||
[Test] | ||
public void ThenReturnsViewResults() | ||
{ | ||
getResult.Should().NotBeNull(); | ||
getResult.ViewName.Should().Be(CheckYourAnswersController.ViewPath); | ||
} | ||
|
||
[Test] | ||
public void ThenSetsRegionToNullInViewModel() | ||
{ | ||
viewModel.Region.Should().BeEmpty(); | ||
} | ||
|
||
[TearDown] | ||
public void Dispose() | ||
{ | ||
sut = null!; | ||
getResult = null!; | ||
viewModel = null!; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...Onboarding/CheckYourAnswersControllerTests/WhenGetIsInvoked/AndSessionModelIsPopulated.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,101 @@ | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using SFA.DAS.Employer.Aan.Domain.Interfaces; | ||
using SFA.DAS.Employer.Aan.Web.Controllers.Onboarding; | ||
using SFA.DAS.Employer.Aan.Web.Infrastructure; | ||
using SFA.DAS.Employer.Aan.Web.Models; | ||
using SFA.DAS.Employer.Aan.Web.Models.Onboarding; | ||
using SFA.DAS.Employer.Aan.Web.UnitTests.TestHelpers; | ||
|
||
namespace SFA.DAS.Employer.Aan.Web.UnitTests.Controllers.Onboarding.CheckYourAnswersControllerTests.WhenGetIsInvoked; | ||
|
||
public class AndSessionModelIsPopulated | ||
{ | ||
OnboardingSessionModel sessionModel; | ||
CheckYourAnswersController sut; | ||
ViewResult getResult; | ||
CheckYourAnswersViewModel viewModel; | ||
|
||
static readonly string RegionUrl = Guid.NewGuid().ToString(); | ||
static readonly string LocallyPreferredRegion = Guid.NewGuid().ToString(); | ||
static readonly List<RegionModel> MultipleRegionsSelected = new() | ||
{ | ||
new RegionModel() { Area = LocallyPreferredRegion, IsSelected = true, IsConfirmed = true}, | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false}, | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false}, | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false} | ||
}; | ||
|
||
static readonly List<RegionModel> SingleRegionSelected = new() | ||
{ | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false}, | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false}, | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false}, | ||
new RegionModel() { Area = Guid.NewGuid().ToString(), IsSelected = true, IsConfirmed = false} | ||
}; | ||
|
||
[SetUp] | ||
public void Init() | ||
{ | ||
sessionModel = new(); | ||
Mock<ISessionService> sessionServiceMock = new(); | ||
sessionServiceMock.Setup(s => s.Get<OnboardingSessionModel>()).Returns(sessionModel); | ||
sut = new(sessionServiceMock.Object); | ||
|
||
sut.AddUrlHelperMock() | ||
.AddUrlForRoute(RouteNames.Onboarding.Regions, RegionUrl); | ||
|
||
sessionModel.Regions = MultipleRegionsSelected; | ||
InvokeControllerGet(); | ||
} | ||
|
||
private void InvokeControllerGet() | ||
{ | ||
getResult = sut.Get().As<ViewResult>(); | ||
viewModel = getResult.Model.As<CheckYourAnswersViewModel>(); | ||
} | ||
|
||
[Test] | ||
public void ThenReturnsViewResults() | ||
{ | ||
InvokeControllerGet(); | ||
getResult.Should().NotBeNull(); | ||
getResult.ViewName.Should().Be(CheckYourAnswersController.ViewPath); | ||
} | ||
|
||
[Test] | ||
public void ThenSetsRegionChangeLinkInViewModel() | ||
{ | ||
InvokeControllerGet(); | ||
viewModel.RegionChangeLink.Should().Be(RegionUrl); | ||
} | ||
|
||
[Test] | ||
public void ThenSetsSingleRegionInViewModel() | ||
{ | ||
sessionModel.Regions = SingleRegionSelected; | ||
InvokeControllerGet(); | ||
viewModel.Region.Should().Equal(SingleRegionSelected.Where(x => x.IsSelected).Select(x => x.Area).ToList()); | ||
} | ||
|
||
[Test] | ||
public void ThenSetsLocallyPreferredRegionInViewModel() | ||
{ | ||
sessionModel.Regions = MultipleRegionsSelected; | ||
InvokeControllerGet(); | ||
var result = MultipleRegionsSelected.Where(x => x.IsSelected).Select(x => x.Area).ToList(); | ||
result.Add($"Locally prefers {LocallyPreferredRegion}"); | ||
|
||
viewModel.Region.Should().Equal(result); | ||
} | ||
|
||
[TearDown] | ||
public void Dispose() | ||
{ | ||
sessionModel = null!; | ||
sut = null!; | ||
getResult = null!; | ||
viewModel = null!; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/SFA.DAS.Employer.Aan.Web/Controllers/Onboarding/CheckYourAnswersController.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,29 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using SFA.DAS.Employer.Aan.Domain.Interfaces; | ||
using SFA.DAS.Employer.Aan.Web.Infrastructure; | ||
using SFA.DAS.Employer.Aan.Web.Models.Onboarding; | ||
|
||
namespace SFA.DAS.Employer.Aan.Web.Controllers.Onboarding; | ||
|
||
[Route("onboarding/check-your-answers", Name = RouteNames.Onboarding.CheckYourAnswers)] | ||
public class CheckYourAnswersController : Controller | ||
{ | ||
public const string ViewPath = "~/Views/Onboarding/CheckYourAnswers.cshtml"; | ||
private readonly ISessionService _sessionService; | ||
|
||
public CheckYourAnswersController(ISessionService sessionService) | ||
{ | ||
_sessionService = sessionService; | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Get() | ||
{ | ||
var sessionModel = _sessionService.Get<OnboardingSessionModel>(); | ||
sessionModel.HasSeenPreview = true; | ||
_sessionService.Set(sessionModel); | ||
|
||
CheckYourAnswersViewModel model = new(Url, sessionModel); | ||
return View(ViewPath, model); | ||
} | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
src/SFA.DAS.Employer.Aan.Web/Models/Onboarding/CheckYourAnswersViewModel.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,28 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using SFA.DAS.Employer.Aan.Web.Infrastructure; | ||
|
||
namespace SFA.DAS.Employer.Aan.Web.Models.Onboarding; | ||
|
||
public class CheckYourAnswersViewModel | ||
{ | ||
public string RegionChangeLink { get; } | ||
public List<string>? Region { get; } | ||
|
||
public CheckYourAnswersViewModel(IUrlHelper url, OnboardingSessionModel sessionModel) | ||
{ | ||
RegionChangeLink = url.RouteUrl(@RouteNames.Onboarding.Regions)!; | ||
Region = GetRegions(sessionModel); | ||
} | ||
|
||
private List<string>? GetRegions(OnboardingSessionModel sessionModel) | ||
{ | ||
var locallyPreferredRegion = sessionModel.Regions.Find(x => x.IsConfirmed); | ||
var regions = sessionModel.Regions.Where(x => x.IsSelected).Select(x => x.Area).ToList()!; | ||
|
||
if (locallyPreferredRegion != null && sessionModel.Regions.Count(x => x.IsSelected) > 1) | ||
{ | ||
regions.Add($"Locally prefers {locallyPreferredRegion.Area}"); | ||
} | ||
return regions!; | ||
} | ||
} |
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.