Exemplo n.º 1
0
        public async Task StopApprenticeshipConfirmation_POST_DataEnteredCorrectly_SubmitsStopToApiAndSucceeds([Frozen] Mock <IEmployerCommitmentsService> api, StopApprovalsController sut, StopApprenticeshipViewModel model, List <StopApprenticeshipRow> 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.StopApprenticeship(
                          It.Is <StopApprenticeshipRequest>(r => apprenticeshipIds.Contains(r.ApprenticeshipId)), It.IsAny <CancellationToken>()))
            .Returns((StopApprenticeshipRequest request, CancellationToken token) =>
            {
                return(Task.FromResult(new StopApprenticeshipResult
                {
                    ApprenticeshipId = request.ApprenticeshipId
                }));
            });

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

            //Then

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

            resultModel.Apprenticeships.All(s => s.ApiSubmissionStatus == SubmissionStatus.Successful);
            resultModel.HasError.Should().BeFalse();
        }
Exemplo n.º 2
0
        public async Task StopApprenticeshipConfirmation_POST_JsonDataError_ReturnsErrorViewModel(StopApprovalsController sut, StopApprenticeshipViewModel model)
        {
            //Given
            model.ApprenticeshipsData = "RandomData";

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

            //Then
            var resultModel = result.Should().BeOfType <ViewResult>().Which
                              .Model.Should().BeOfType <StopApprenticeshipViewModel>().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");
        }
Exemplo n.º 3
0
        public async Task StopApprenticeshipConfirmation_POST_NotAllStopDatesEntered_ReturnsErrorViewModel(StopApprovalsController sut, StopApprenticeshipViewModel model, List <StopApprenticeshipRow> apprenticeshipData)
        {
            //Given
            var jsonData = JsonSerializer.Serialize(apprenticeshipData, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            }).ToString();

            model.ApprenticeshipsData = jsonData;

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

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

            resultModel.ApprenticeshipsData.Should().BeSameAs(model.ApprenticeshipsData);
            sut.ModelState.IsValid.Should().BeFalse();
            sut.ModelState.Values.First().Errors.First().ErrorMessage.Should().Be("Not all Apprenticeship rows have been supplied with a stop date.");
        }
Exemplo n.º 4
0
        public async Task StopApprenticeshipConfirmation_POST_IdentityError_ReturnsErrorViewModel(StopApprovalsController sut, StopApprenticeshipViewModel model, List <StopApprenticeshipRow> 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.StopApprenticeshipConfirmation(model);

            //Then
            var resultModel = result.Should().BeOfType <ViewResult>().Which
                              .Model.Should().BeOfType <StopApprenticeshipViewModel>().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 stop apprenticeship");
        }