public async Task PauseApprenticeshipConfirmation_POST_DataEnteredCorrectly_SubmitsPauseToApiAndSucceeds([Frozen] Mock <IEmployerCommitmentsService> api, PauseApprovalsController sut, PauseApprenticeshipViewModel model, List <PauseApprenticeshipRow> apprenticeshipData)
        {
            //Given
            //apprenticeshipData.ForEach(s => s.EnteredDate = DateTime.Today.ToString("yyyy-MM-dd"));
            var apprenticeshipIds = apprenticeshipData.Select(s => s.Id);
            var jsonData          = JsonSerializer.Serialize(apprenticeshipData, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            }).ToString();

            model.ApprenticeshipsData = jsonData;

            api.Setup(s => s.PauseApprenticeship(
                          It.Is <PauseApprenticeshipRequest>(r => apprenticeshipIds.Contains(r.ApprenticeshipId)), It.IsAny <CancellationToken>()))
            .Returns((PauseApprenticeshipRequest request, CancellationToken token) =>
            {
                return(Task.FromResult(new PauseApprenticeshipResult
                {
                    ApprenticeshipId = request.ApprenticeshipId
                }));
            });

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

            //Then

            var resultModel = result.Should().BeOfType <ViewResult>().Which
                              .Model.Should().BeOfType <PauseApprenticeshipViewModel>().Which;

            resultModel.Apprenticeships.All(s => s.ApiSubmissionStatus == SubmissionStatus.Successful);
            resultModel.HasError.Should().BeFalse();
        }
        public async Task PauseApprenticeshipConfirmation_POST_JsonDataError_ReturnsErrorViewModel(PauseApprovalsController sut, PauseApprenticeshipViewModel model)
        {
            //Given
            model.ApprenticeshipsData = "RandomData";

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

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

            resultModel.ApprenticeshipsData.Should().BeSameAs(null);
            sut.ModelState.IsValid.Should().BeFalse();
            sut.ModelState.Values.First().Errors.First().ErrorMessage.Should().Be("Unable to Read apprenticeship information, please return to the search and try again");
        }
        public async Task PauseApprenticeshipConfirmation_POST_IdentityError_ReturnsErrorViewModel(PauseApprovalsController sut, PauseApprenticeshipViewModel model, List <PauseApprenticeshipRow> apprenticeshipData)
        {
            //Given
            var jsonData = JsonSerializer.Serialize(apprenticeshipData, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            }).ToString();

            model.ApprenticeshipsData         = jsonData;
            sut.ControllerContext.HttpContext = new DefaultHttpContext();

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

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

            resultModel.ApprenticeshipsData.Should().BeSameAs(model.ApprenticeshipsData);
            sut.ModelState.IsValid.Should().BeFalse();
            sut.ModelState.Values.First().Errors.First().ErrorMessage.Should().Be("Unable to retrieve userId or name from claim for request to Pause Apprenticeship");
        }