示例#1
0
        public async Task StopApprenticeship_POST_NoRowsSelected_RedirectsToSearch(StopApprovalsController sut, ApprenticeshipSearchResultsViewModel model)
        {
            //Given
            model.SelectedIds = null;

            //When
            var result = await sut.StopApprenticeship(model);

            //Then
            var action = result.Should().BeOfType <RedirectToActionResult>().Which;

            action.ActionName.Should().Be(RouteNames.Approval_SearchApprenticeships);
            action.RouteValues.Values.Should().BeEquivalentTo(new object []
            {
                model.ApprenticeNameOrUln,
                model.CourseName,
                model.ProviderName,
                model.Ukprn,
                model.EmployerName,
                model.Status,
                model.EndDate.Value.ToString("yyyy-MM-dd"),
                model.StartDate.Value.ToString("yyyy-MM-dd"),
                StopAction
            });
        }
示例#2
0
        public async Task StopApprenticeship_POST_ApiErrorOccurs_ReturnsErrorViewModel([Frozen] Mock <IEmployerCommitmentsService> api, StopApprovalsController sut, ApprenticeshipSearchResultsViewModel model)
        {
            //Given
            var fixture           = new Fixture();
            var apprenticeResults = fixture.CreateMany <GetApprenticeshipResult>(3).ToList();
            var ids = apprenticeResults.Select(s => s.Apprenticeship.Id);

            apprenticeResults.ForEach(a => a.ErrorMessage = string.Empty);
            apprenticeResults.Last().ErrorMessage = "Api ErrorMessage";
            model.SelectedIds = ids.Aggregate <long, string>("", (current, value) => current + "," + value.ToString());
            api.Setup(a => a.GetApprenticeship(It.Is <long>(a => ids.Contains(a)), It.IsAny <CancellationToken>())).Returns((long id, CancellationToken token) =>
                                                                                                                            Task.FromResult(apprenticeResults.Where(s => s.Apprenticeship.Id == id).FirstOrDefault()));

            //When
            var result = await sut.StopApprenticeship(model);

            //Then
            result.Should().BeOfType <ViewResult>().Which
            .Model.Should().BeOfType <StopApprenticeshipViewModel>().Which
            .HasError.Should().BeTrue();
        }
示例#3
0
        public async Task StopApprenticeship_POST_ApiReturnsResults_ReturnsViewModel([Frozen] Mock <IEmployerCommitmentsService> api, StopApprovalsController sut, ApprenticeshipSearchResultsViewModel model)
        {
            //Given
            var fixture           = new Fixture();
            var apprenticeResults = fixture.CreateMany <GetApprenticeshipResult>(3).ToList();
            var ids = apprenticeResults.Select(s => s.Apprenticeship.Id);

            apprenticeResults.ForEach(a => a.ErrorMessage = string.Empty);
            model.SelectedIds = ids.Aggregate <long, string>("", (current, value) => current + "," + value.ToString());
            api.Setup(a => a.GetApprenticeship(It.Is <long>(a => ids.Contains(a)), It.IsAny <CancellationToken>()))
            .Returns((long id, CancellationToken token) => Task.FromResult(apprenticeResults.Where(s => s.Apprenticeship.Id == id).FirstOrDefault()));

            //When
            var result = await sut.StopApprenticeship(model);

            //Then
            var resultModel = result.Should().BeOfType <ViewResult>().Which
                              .Model.Should().BeOfType <StopApprenticeshipViewModel>().Which;

            resultModel.SearchParams.Should().BeEquivalentTo(new
            {
                model.ApprenticeNameOrUln,
                model.CourseName,
                model.EmployerName,
                model.ProviderName,
                model.Ukprn,
                SelectedStatus = model.Status,
                model.StartDate,
                model.EndDate
            });

            resultModel.Apprenticeships.Should().BeEquivalentTo(new object[]
            {
                new {
                    apprenticeResults[0].Apprenticeship.Id,
                    AccountId = apprenticeResults[0].Apprenticeship.EmployerAccountId,
                    apprenticeResults[0].Apprenticeship.FirstName,
                    apprenticeResults[0].Apprenticeship.LastName,
                    apprenticeResults[0].Apprenticeship.Uln,
                    apprenticeResults[0].Apprenticeship.EmployerName,
                    apprenticeResults[0].Apprenticeship.ProviderName,
                    apprenticeResults[0].Apprenticeship.Ukprn,
                    apprenticeResults[0].Apprenticeship.CourseName,
                    Status        = apprenticeResults[0].Apprenticeship.ApprenticeshipStatus.ToString(),
                    PaymentStatus = apprenticeResults[0].Apprenticeship.PaymentStatus.ToString(),
                    apprenticeResults[0].Apprenticeship.StartDate,
                    apprenticeResults[0].Apprenticeship.EndDate,
                    ApiSubmissionStatus = SubmissionStatus.NotSent
                },
                new {
                    apprenticeResults[1].Apprenticeship.Id,
                    AccountId = apprenticeResults[1].Apprenticeship.EmployerAccountId,
                    apprenticeResults[1].Apprenticeship.FirstName,
                    apprenticeResults[1].Apprenticeship.LastName,
                    apprenticeResults[1].Apprenticeship.Uln,
                    apprenticeResults[1].Apprenticeship.EmployerName,
                    apprenticeResults[1].Apprenticeship.ProviderName,
                    apprenticeResults[1].Apprenticeship.Ukprn,
                    apprenticeResults[1].Apprenticeship.CourseName,
                    Status        = apprenticeResults[1].Apprenticeship.ApprenticeshipStatus.ToString(),
                    PaymentStatus = apprenticeResults[1].Apprenticeship.PaymentStatus.ToString(),
                    apprenticeResults[1].Apprenticeship.StartDate,
                    apprenticeResults[1].Apprenticeship.EndDate,
                    ApiSubmissionStatus = SubmissionStatus.NotSent
                },
                new {
                    apprenticeResults[2].Apprenticeship.Id,
                    AccountId = apprenticeResults[2].Apprenticeship.EmployerAccountId,
                    apprenticeResults[2].Apprenticeship.FirstName,
                    apprenticeResults[2].Apprenticeship.LastName,
                    apprenticeResults[2].Apprenticeship.Uln,
                    apprenticeResults[2].Apprenticeship.EmployerName,
                    apprenticeResults[2].Apprenticeship.ProviderName,
                    apprenticeResults[2].Apprenticeship.Ukprn,
                    apprenticeResults[2].Apprenticeship.CourseName,
                    Status        = apprenticeResults[2].Apprenticeship.ApprenticeshipStatus.ToString(),
                    PaymentStatus = apprenticeResults[2].Apprenticeship.PaymentStatus.ToString(),
                    apprenticeResults[2].Apprenticeship.StartDate,
                    apprenticeResults[2].Apprenticeship.EndDate,
                    ApiSubmissionStatus = SubmissionStatus.NotSent
                }
            });
        }