public async Task <IcoNumberViewModel> GetIcoNumberViewModel(GetIcoNumberRequest request)
        {
            _logger.LogInformation($"Retrieving ICO Number check details for application {request.ApplicationId}");

            var model = new IcoNumberViewModel();
            await model.PopulatePageCommonDetails(_applyApiClient, request.ApplicationId, GatewaySequences.OrganisationChecks,
                                                  GatewayPageIds.IcoNumber,
                                                  request.UserId,
                                                  request.UserName,
                                                  RoatpGatewayConstants.Captions.OrganisationChecks,
                                                  RoatpGatewayConstants.Headings.IcoNumber,
                                                  NoSelectionErrorMessages.Errors[GatewayPageIds.IcoNumber]);


            var organisationAddress = await _applyApiClient.GetOrganisationAddress(request.ApplicationId);

            if (organisationAddress != null)
            {
                var AddressArray = new[] { organisationAddress.Address1, organisationAddress.Address2, organisationAddress.Address3, organisationAddress.Address4, organisationAddress.Town, organisationAddress.PostCode };
                model.OrganisationAddress = string.Join(", ", AddressArray.Where(s => !string.IsNullOrEmpty(s)));
            }

            var icoNumber = await _applyApiClient.GetIcoNumber(request.ApplicationId);

            model.IcoNumber = icoNumber.Value;

            return(model);
        }
        public async Task IcoNumber_saves_clarification_result()
        {
            var applicationId = Guid.NewGuid();
            var pageId        = GatewayPageIds.IcoNumber;

            var vm = new IcoNumberViewModel
            {
                ApplicationId       = applicationId,
                PageId              = pageId,
                Status              = SectionReviewStatus.Pass,
                SourcesCheckedOn    = DateTime.Now,
                ErrorMessages       = new List <ValidationErrorDetail>(),
                OptionPassText      = "Some pass text",
                ClarificationAnswer = ClarificationAnswer
            };

            var command = new SubmitGatewayPageAnswerCommand(vm);

            GatewayValidator.Setup(v => v.ValidateClarification(command)).ReturnsAsync(new ValidationResponse {
                Errors = new List <ValidationErrorDetail>()
            });

            await _controller.ClarifyIcoNumberPage(command);

            ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswerPostClarification(applicationId, pageId, vm.Status, UserId, Username, vm.OptionPassText, ClarificationAnswer));
        }
        public async Task IcoNumber_without_required_fields_does_not_save()
        {
            var applicationId = Guid.NewGuid();
            var pageId        = GatewayPageIds.IcoNumber;

            var vm = new IcoNumberViewModel()
            {
                Status           = SectionReviewStatus.Fail,
                SourcesCheckedOn = DateTime.Now,
                ErrorMessages    = new List <ValidationErrorDetail>(),
                ApplicationId    = applicationId,
                PageId           = pageId
            };

            var command = new SubmitGatewayPageAnswerCommand(vm);

            GatewayValidator.Setup(v => v.Validate(command))
            .ReturnsAsync(new ValidationResponse
            {
                Errors = new List <ValidationErrorDetail>
                {
                    new ValidationErrorDetail {
                        Field = "OptionFail", ErrorMessage = "needs text"
                    }
                }
            }
                          );

            _orchestrator.Setup(x => x.GetIcoNumberViewModel(It.Is <GetIcoNumberRequest>(y => y.ApplicationId == vm.ApplicationId &&
                                                                                         y.UserName == Username))).ReturnsAsync(vm);

            await _controller.EvaluateIcoNumberPage(command);

            ApplyApiClient.Verify(x => x.SubmitGatewayPageAnswer(applicationId, pageId, vm.Status, UserId, Username, null), Times.Never);
        }
        public async Task IcoNumber_details_are_returned()
        {
            var applicationId     = Guid.NewGuid();
            var expectedViewModel = new IcoNumberViewModel();

            _orchestrator.Setup(x => x.GetIcoNumberViewModel(It.Is <GetIcoNumberRequest>(y => y.ApplicationId == applicationId && y.UserName == Username))).ReturnsAsync(expectedViewModel);

            var result = await _controller.GetIcoNumberPage(applicationId);

            var viewResult = result as ViewResult;

            Assert.AreSame(expectedViewModel, viewResult.Model);
        }