Exemple #1
0
        public async Task And_All_Versions_Are_Selected_Then_Server_Withdrawal_Is_Used()
        {
            // Arrange
            var applicationId = Guid.NewGuid();

            _mockApplicationApiClient.Setup(m => m.GetWithdrawalApplications(It.IsAny <Guid>()))
            .ReturnsAsync(new List <ApplicationResponse>()
            {
                new ApplicationResponse()
                {
                    Id = applicationId,
                    ApplicationStatus = ApplicationStatus.InProgress,
                    ApplicationType   = ApplicationTypes.StandardWithdrawal,
                    StandardReference = "ST0001",
                    ApplyData         = new ApplyData()
                    {
                        Apply = new ApplyTypes.Apply()
                        {
                            StandardReference = "ST0001", Versions = new List <string> {
                                "1.0"
                            }
                        }
                    }
                }
            });

            _mockStandardVersionApiClient.Setup(m => m.GetEpaoRegisteredStandardVersions(It.IsAny <string>(), "ST0001"))
            .ReturnsAsync(new List <StandardVersion>()
            {
                new StandardVersion()
                {
                    Version = "1.0"
                },
                new StandardVersion()
                {
                    Version = "1.1"
                },
                new StandardVersion()
                {
                    Version = "1.2"
                }
            });

            var model = new ChooseStandardVersionForWithdrawalViewModel()
            {
                SelectedVersions = new List <string>()
                {
                    "1.1", "1.2"
                }
            };

            // Act
            var result = await _sut.ChooseStandardVersionForWithdrawal("ST0001", model) as RedirectToActionResult;

            // Assert
            result.ActionName.Should().Be(nameof(ApplyForWithdrawalController.CheckWithdrawalRequest));
            result.ControllerName.Should().Be(nameof(ApplyForWithdrawalController).RemoveController());
            result.RouteValues.GetValueOrDefault("iFateReferenceNumber").Should().Be("ST0001");
            result.RouteValues.GetValueOrDefault("versionsToWithdrawal").Should().BeNull();
        }
Exemple #2
0
        public async Task And_No_Versions_Are_Selected_Then_Error_Is_Returned()
        {
            // Arrange
            var applicationId = Guid.NewGuid();

            _mockApplicationApiClient.Setup(m => m.GetWithdrawalApplications(It.IsAny <Guid>()))
            .ReturnsAsync(new List <ApplicationResponse>()
            {
                new ApplicationResponse()
                {
                    Id = applicationId,
                    ApplicationStatus = ApplicationStatus.InProgress,
                    ApplyData         = new ApplyData()
                    {
                        Apply = new ApplyTypes.Apply()
                        {
                            StandardReference = "ST0001", Versions = new List <string> {
                                "1.0"
                            }
                        }
                    }
                }
            });

            _mockStandardVersionApiClient.Setup(m => m.GetEpaoRegisteredStandardVersions(It.IsAny <string>(), "ST0001"))
            .ReturnsAsync(new List <StandardVersion>()
            {
                new StandardVersion()
                {
                    Version = "1.0"
                },
                new StandardVersion()
                {
                    Version = "1.1"
                },
                new StandardVersion()
                {
                    Version = "1.2"
                },
                new StandardVersion()
                {
                    Version = "1.3"
                }
            });

            var model = new ChooseStandardVersionForWithdrawalViewModel()
            {
                SelectedVersions = new List <string>()
            };

            // Act
            var result = await _sut.ChooseStandardVersionForWithdrawal("ST0001", model) as RedirectToActionResult;

            // Assert
            _sut.ModelState.IsValid.Should().BeFalse();
            _sut.ModelState["SelectedVersions"].Errors.Should().Contain(x => x.ErrorMessage == "Select at least one version");
        }
        public async Task <IActionResult> ChooseStandardVersionForWithdrawal(string iFateReferenceNumber)
        {
            var contact = await GetUserContact();

            var organisation = await _orgApiClient.GetOrganisationByUserId(contact.Id);

            var applications = await GetWithdrawalApplications(contact.Id, iFateReferenceNumber);

            var versions = await _standardVersionApiClient.GetEpaoRegisteredStandardVersions(organisation.EndPointAssessorOrganisationId, iFateReferenceNumber);

            var standard = versions.First();

            var viewModel = new ChooseStandardVersionForWithdrawalViewModel()
            {
                IFateReferenceNumber = iFateReferenceNumber,
                Level        = standard.Level,
                StandardName = standard.Title,
                Versions     = versions.Where(v => !applications.Any(a => a.ApplyData.Apply.Versions != null && a.ApplyData.Apply.Versions.Contains(v.Version)))
                               .OrderByDescending(x => x.Version)
                               .ToList(),
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> ChooseStandardVersionForWithdrawal(string iFateReferenceNumber, ChooseStandardVersionForWithdrawalViewModel model)
        {
            var contact = await GetUserContact();

            var organisation = await _orgApiClient.GetOrganisationByUserId(contact.Id);

            var applications = await GetWithdrawalApplications(contact.Id, iFateReferenceNumber);

            var versions = (await _standardVersionApiClient.GetEpaoRegisteredStandardVersions(organisation.EndPointAssessorOrganisationId, iFateReferenceNumber))
                           .Where(v => !applications.Any(a => a.ApplyData.Apply.Versions != null && a.ApplyData.Apply.Versions.Contains(v.Version)))
                           .OrderByDescending(x => x.Version)
                           .ToList();

            var standard = versions.First();

            if (model.SelectedVersions == null || !model.SelectedVersions.Any())
            {
                ModelState.AddModelError(nameof(model.SelectedVersions), "Select at least one version");
            }

            if (!ModelState.IsValid)
            {
                model.IFateReferenceNumber = iFateReferenceNumber;
                model.Level        = standard.Level;
                model.StandardName = standard.Title;
                model.Versions     = versions;
                return(View(model));
            }
            else if (model.SelectedVersions.Count == versions.Count)
            {
                return(RedirectToAction(
                           nameof(CheckWithdrawalRequest),
                           nameof(ApplyForWithdrawalController).RemoveController(),
                           new { iFateReferenceNumber = iFateReferenceNumber, backAction = nameof(ChooseStandardVersionForWithdrawal) }));
            }
            else
            {
                var selectedVersions = model.SelectedVersions
                                       .OrderBy(x => decimal.Parse(x));

                return(RedirectToAction(
                           nameof(CheckWithdrawalRequest),
                           nameof(ApplyForWithdrawalController).RemoveController(),
                           new { iFateReferenceNumber = iFateReferenceNumber, versionsToWithdrawal = string.Join(",", selectedVersions), backAction = nameof(ChooseStandardVersionForWithdrawal) }));
            }
        }