示例#1
0
        public async Task WhenTheEmployerUpdatesApplicationWithNoApprenticesSelected()
        {
            var hashedAccountId = _hashingService.HashValue(_data.AccountId);
            var url             = $"{hashedAccountId}/apply/select-apprentices/{_data.ApplicationId}";
            var form            = new SelectApprenticeshipsRequest();

            _response = await _testContext.WebsiteClient.PostAsJsonAsync(url, form);
        }
        public async Task <IActionResult> Confirm(SelectApprenticeshipsRequest request)
        {
            if (!request.HasSelectedApprenticeships)
            {
                var viewModel = await GetSelectViewModel(request.AccountId, request.AccountLegalEntityId);

                ModelState.AddModelError(viewModel.FirstCheckboxId, viewModel.SelectApprenticeshipsMessage);

                return(View("SelectApprenticeships", viewModel));
            }

            return(View("ConfirmApprentices", await GetConfirmViewModel(request)));
        }
        public async Task Arrange()
        {
            _apprenticeshipIncentiveData = new Fixture().CreateMany <ApprenticeshipIncentiveModel>();
            _hashedAccountId             = Guid.NewGuid().ToString();
            _hashedAccountLegalEntityId  = Guid.NewGuid().ToString();
            _organisationName            = Guid.NewGuid().ToString();

            _mockLegalEntitiesService = new Mock <ILegalEntitiesService>();
            _mockLegalEntitiesService
            .Setup(m => m.Get(_hashedAccountId, _hashedAccountLegalEntityId))
            .ReturnsAsync(new LegalEntityModel()
            {
                Name = _organisationName
            });

            _mockApprenticeshipIncentiveService = new Mock <IApprenticeshipIncentiveService>();
            _mockApprenticeshipIncentiveService
            .Setup(m => m.GetList(_hashedAccountId, _hashedAccountLegalEntityId))
            .ReturnsAsync(_apprenticeshipIncentiveData);

            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = _apprenticeshipIncentiveData.Where(a => a.Selected).Select(a => a.Id).ToList()
            };

            _emailAddress = "*****@*****.**";
            var claims = new[] { new Claim(EmployerClaimTypes.EmailAddress, _emailAddress) };
            var user   = new ClaimsPrincipal(new ClaimsIdentity(claims));

            _sut = new Web.Controllers.CancelController(_mockApprenticeshipIncentiveService.Object, _mockLegalEntitiesService.Object)
            {
                TempData          = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>()),
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext {
                        User = user
                    }
                }
            };

            _mockApprenticeshipIncentiveService
            .Setup(m => m.Cancel(_hashedAccountLegalEntityId, _apprenticeshipIncentiveData.Where(a => a.Selected),
                                 _hashedAccountId, _emailAddress))
            .Verifiable();

            _result = await _sut.Cancelled(selected, _hashedAccountId);

            _model = ((ViewResult)_result).Model as CancelledApprenticeshipsViewModel;
        }
        private async Task <CancelledApprenticeshipsViewModel> GetCancelledViewModel(
            SelectApprenticeshipsRequest request,
            IEnumerable <ApprenticeshipIncentiveModel> apprenticeshipIncentives)
        {
            var legalEntity = await _legalEntitiesService.Get(request.AccountId, request.AccountLegalEntityId);

            return(new CancelledApprenticeshipsViewModel
            {
                AccountId = request.AccountId,
                AccountLegalEntityId = request.AccountLegalEntityId,
                ApprenticeshipIncentives = apprenticeshipIncentives.OrderBy(a => a.Uln),
                OrganisationName = legalEntity?.Name ?? string.Empty
            });
        }
        public async Task <IActionResult> SelectApprenticeships(SelectApprenticeshipsRequest form, Guid applicationId)
        {
            if (form.HasSelectedApprenticeships)
            {
                await _applicationService.Update(applicationId, form.AccountId, form.SelectedApprenticeships);

                return(RedirectToAction("ConfirmApprenticeships", new { form.AccountId, applicationId }));
            }

            var viewModel = await GetSelectApprenticeshipsViewModel(form.AccountId, applicationId, false);

            ModelState.AddModelError(viewModel.FirstCheckboxId, SelectApprenticeshipsViewModel.SelectApprenticeshipsMessage);

            return(View(viewModel));
        }
        public async Task <IActionResult> SelectApprenticeships(SelectApprenticeshipsRequest form)
        {
            if (form.HasSelectedApprenticeships)
            {
                var applicationId = await _applicationService.Create(form.AccountId, form.AccountLegalEntityId, form.SelectedApprenticeships);

                return(RedirectToAction("ConfirmApprenticeships", new { form.AccountId, applicationId }));
            }

            var viewModel = await GetInitialSelectApprenticeshipsViewModel(form.AccountId, form.AccountLegalEntityId);

            ModelState.AddModelError(viewModel.FirstCheckboxId, SelectApprenticeshipsViewModel.SelectApprenticeshipsMessage);

            return(View(viewModel));
        }
        public async Task Then_the_ConfirmApprenticeships_page_is_displayed()
        {
            var request = new SelectApprenticeshipsRequest
            {
                SelectedApprenticeships = new List <string> {
                    _apprenticeData.First().Id
                }
            };

            var result         = _sut.SelectApprenticeships(request);
            var redirectResult = await result as RedirectToActionResult;

            redirectResult.Should().NotBeNull();
            redirectResult?.ActionName.Should().Be("ConfirmApprenticeships");
        }
示例#8
0
        public async Task Then_displays_confirmation_page_when_apprenticeships_selected()
        {
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = _apprenticeshipIncentiveData.Select(a => a.Id).ToList()
            };

            // act
            var result = ((ViewResult)await _sut.Confirm(selected)).Model as ConfirmApprenticeshipsViewModel;

            // assert
            result.Should().NotBeNull();
        }
示例#9
0
        public async Task Then_page_title_is_set_if_no_apprenticeships_selected()
        {
            // arrange
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = new List <string>()
            };

            // act
            var result = ((ViewResult)await _sut.Confirm(selected)).Model as SelectApprenticeshipsViewModel;

            // assert
            result.Title.Should().Be("Which apprentices do you want to cancel an application for?");
        }
示例#10
0
        public async Task Then_add_model_error_if_no_apprenticeships_selected()
        {
            // arrange
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = new List <string>()
            };

            // act
            var result = (await _sut.Confirm(selected)) as ViewResult;

            // assert
            result.ViewData.ModelState.ErrorCount.Should().Be(1);
        }
示例#11
0
        public async Task Then_the_employment_start_dates_page_is_displayed()
        {
            var request = new SelectApprenticeshipsRequest
            {
                SelectedApprenticeships = new List <string> {
                    _apprenticeData.First().Id
                }
            };

            var result         = _sut.SelectApprenticeships(request);
            var redirectResult = await result as RedirectToActionResult;

            redirectResult.Should().NotBeNull();
            redirectResult?.ActionName.Should().Be("EmploymentStartDates");
            redirectResult?.ControllerName.Should().Be("ApplyEmploymentDetails");
        }
示例#12
0
        public async Task Then_accountId_is_set_if_no_apprenticeships_selected()
        {
            // arrange
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = new List <string>()
            };

            // act
            var result = ((ViewResult)await _sut.Confirm(selected)).Model as SelectApprenticeshipsViewModel;

            // assert
            result.AccountId.Should().Be(_hashedAccountId);
        }
示例#13
0
        public async Task Then_should_show_error_if_no_selection_is_made()
        {
            var request = new SelectApprenticeshipsRequest()
            {
                AccountLegalEntityId = _hashedLegalEntityId,
                AccountId            = _hashedAccountId
            };
            var result = _sut.SelectApprenticeships(request);

            var viewResult = await result as ViewResult;

            viewResult.Should().NotBeNull();
            _sut.ViewData.ModelState.IsValid.Should().BeFalse();
            _sut.ViewData.ModelState.Single(x => x.Key == _model.FirstCheckboxId).Value.Errors
            .Should().Contain(x => x.ErrorMessage == SelectApprenticeshipsViewModel.SelectApprenticeshipsMessage);
            viewResult?.ViewName.Should().BeNullOrEmpty();
        }
        public async Task <IActionResult> Cancelled(SelectApprenticeshipsRequest request, string accountId)
        {
            if (!request.HasSelectedApprenticeships)
            {
                return(RedirectToAction("ListPaymentsForLegalEntity", "Payments", new { request.AccountId, request.AccountLegalEntityId }));
            }

            var apprenticeshipIncentivesToWithdraw =
                (await GetSelectViewModel(request.AccountId, request.AccountLegalEntityId))
                .ApprenticeshipIncentives.Where(a => a.Selected).ToList();

            var emailAddress = ControllerContext.HttpContext.User.FindFirst(c => c.Type.Equals(EmployerClaimTypes.EmailAddress))?.Value;

            await _apprenticeshipIncentiveService.Cancel(request.AccountLegalEntityId, apprenticeshipIncentivesToWithdraw,
                                                         accountId, emailAddress);

            return(View("ConfirmCancellation", await GetCancelledViewModel(request, apprenticeshipIncentivesToWithdraw)));
        }
示例#15
0
        public async Task <IActionResult> SelectApprenticeships(SelectApprenticeshipsRequest form, Guid applicationId)
        {
            if (form.HasSelectedApprenticeships)
            {
                await _applicationService.Update(applicationId, form.AccountId, form.SelectedApprenticeships);

                return(RedirectToAction("EmploymentStartDates", "ApplyEmploymentDetails", new { form.AccountId, applicationId }));
            }

            var viewModel = await GetSelectApprenticeshipsViewModel(form.AccountId, applicationId, false);

            if (viewModel == null)
            {
                return(RedirectToAction("Home", "Home", new { form.AccountId }));
            }
            ModelState.AddModelError(viewModel.FirstCheckboxId, SelectApprenticeshipsViewModel.SelectApprenticeshipsMessage);

            return(View(viewModel));
        }
        private async Task <ConfirmApprenticeshipsViewModel> GetConfirmViewModel(SelectApprenticeshipsRequest request)
        {
            var viewModel = await GetSelectViewModel(request.AccountId, request.AccountLegalEntityId);

            TempData.Add("selected", request.SelectedApprenticeships);

            return(new ConfirmApprenticeshipsViewModel
            {
                AccountId = viewModel.AccountId,
                AccountLegalEntityId = viewModel.AccountLegalEntityId,
                ApprenticeshipIncentives = viewModel
                                           .ApprenticeshipIncentives
                                           .Where(a => request.SelectedApprenticeships.Contains(a.Id))
                                           .OrderBy(a => a.FirstName)
                                           .ThenBy(a => a.LastName)
                                           .ThenBy(a => a.Uln),
                OrganisationName = viewModel.OrganisationName
            });
        }
        public async Task Then_redirects_to_payments_page_when_no_apprenticeships_selected()
        {
            // arrange
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = new List <string>()
            };

            // act
            var result = (await _sut.Cancelled(selected, _hashedAccountId)) as RedirectToActionResult;

            // assert
            result.ControllerName.Should().Be("Payments");
            result.ActionName.Should().Be("ListPaymentsForLegalEntity");
            result.RouteValues["accountId"].Should().Be(_hashedAccountId);
            result.RouteValues["accountLegalEntityId"].Should().Be(_hashedAccountLegalEntityId);
        }
示例#18
0
        public async Task Then_should_show_error_if_no_selection_is_made()
        {
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = new List <string>()
            };

            // act
            var result = ((ViewResult)await _sut.Confirm(selected));
            var model  = result.Model as SelectApprenticeshipsViewModel;

            // assert
            model.Should().NotBeNull();
            result.ViewData.ModelState.IsValid.Should().BeFalse();
            result.ViewData.ModelState.Single(x => x.Key == model.FirstCheckboxId).Value.Errors
            .Should().Contain(x => x.ErrorMessage == (new SelectApprenticeshipsViewModel()).SelectApprenticeshipsMessage);
        }
示例#19
0
        public async Task Then_should_display_a_list_of_apprentices()
        {
            // arrange
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = new List <string>()
            };

            // act
            var result = ((ViewResult)await _sut.Confirm(selected)).Model as SelectApprenticeshipsViewModel;

            // assert
            result.ApprenticeshipIncentives.Should()
            .BeEquivalentTo(_apprenticeshipIncentiveData,
                            opt => opt
                            .Excluding(x => x.Id)
                            .Excluding(x => x.DisplayName)
                            );
        }
示例#20
0
        public async Task Then_should_have_apprentices_ordered_by_first_name_last_name_uln()
        {
            // arrange
            var selected = new SelectApprenticeshipsRequest()
            {
                AccountId               = _hashedAccountId,
                AccountLegalEntityId    = _hashedAccountLegalEntityId,
                SelectedApprenticeships = _apprenticeshipIncentiveData.Select(a => a.Id).ToList()
            };

            // act
            var result = ((ViewResult)await _sut.Confirm(selected)).Model as ConfirmApprenticeshipsViewModel;

            // assert
            var expectedResults = _apprenticeshipIncentiveData
                                  .OrderBy(a => a.FirstName)
                                  .ThenBy(a => a.LastName)
                                  .ThenBy(a => a.Uln);

            result.ApprenticeshipIncentives.Should().ContainInOrder(expectedResults);
        }