예제 #1
0
        public async Task Then_New_Account_Is_Not_Created()
        {
            await _employerAccountOrchestrator.CreateOrUpdateAccount(ArrangeModel(),
                                                                     It.IsAny <HttpContextBase>());

            _mediator
            .Verify(
                x => x.SendAsync(
                    It.IsAny <CreateAccountCommand>()
                    ),
                Times.Never);
        }
        public async Task <ActionResult> CreateAccount()
        {
            var enteredData = _employerAccountOrchestrator.GetCookieData();

            if (enteredData == null)
            {
                // N.B CHANGED THIS FROM SelectEmployer which went nowhere.
                _employerAccountOrchestrator.DeleteCookieData();

                return(RedirectToAction(ControllerConstants.SearchForOrganisationActionName, ControllerConstants.SearchOrganisationControllerName));
            }

            var request = new CreateAccountModel
            {
                UserId                      = GetUserId(),
                OrganisationType            = enteredData.EmployerAccountOrganisationData.OrganisationType,
                OrganisationReferenceNumber = enteredData.EmployerAccountOrganisationData.OrganisationReferenceNumber,
                OrganisationName            = enteredData.EmployerAccountOrganisationData.OrganisationName,
                OrganisationAddress         = enteredData.EmployerAccountOrganisationData.OrganisationRegisteredAddress,
                OrganisationDateOfInception = enteredData.EmployerAccountOrganisationData.OrganisationDateOfInception,
                PayeReference               = enteredData.EmployerAccountPayeRefData.PayeReference,
                AccessToken                 = enteredData.EmployerAccountPayeRefData.AccessToken,
                RefreshToken                = enteredData.EmployerAccountPayeRefData.RefreshToken,
                OrganisationStatus          = string.IsNullOrWhiteSpace(enteredData.EmployerAccountOrganisationData.OrganisationStatus) ? null : enteredData.EmployerAccountOrganisationData.OrganisationStatus,
                EmployerRefName             = enteredData.EmployerAccountPayeRefData.EmployerRefName,
                PublicSectorDataSource      = enteredData.EmployerAccountOrganisationData.PublicSectorDataSource,
                Sector                      = enteredData.EmployerAccountOrganisationData.Sector,
                HashedAccountId             = _accountCookieStorage.Get(_hashedAccountIdCookieName),
                Aorn = enteredData.EmployerAccountPayeRefData.AORN
            };

            var response = await _employerAccountOrchestrator.CreateOrUpdateAccount(request, HttpContext);

            if (response.Status == HttpStatusCode.BadRequest)
            {
                response.Status       = HttpStatusCode.OK;
                response.FlashMessage = new FlashMessageViewModel {
                    Headline = "There was a problem creating your account"
                };
                return(RedirectToAction(ControllerConstants.SummaryActionName));
            }

            _employerAccountOrchestrator.DeleteCookieData();

            var returnUrlCookie = _returnUrlCookieStorageService.Get(ReturnUrlCookieName);

            _accountCookieStorage.Delete(_hashedAccountIdCookieName);

            _returnUrlCookieStorageService.Delete(ReturnUrlCookieName);

            if (returnUrlCookie != null && !returnUrlCookie.Value.IsNullOrWhiteSpace())
            {
                return(Redirect(returnUrlCookie.Value));
            }

            return(RedirectToAction(ControllerConstants.WhenDoYouWantToView, ControllerConstants.EmployerAgreementControllerName, new { hashedAccountId = response.Data.EmployerAgreement.HashedAccountId, agreementId = response.Data.EmployerAgreement.HashedAgreementId }));
        }
        public async Task ThenTheMediatorCommandIsCalledWithCorrectParameters()
        {
            //Arrange
            var model = ArrangeModel();

            //Act
            await _employerAccountOrchestrator.CreateOrUpdateAccount(model, It.IsAny <HttpContextBase>());

            //Assert
            _mediator.Verify(x => x.SendAsync(It.Is <CreateAccountCommand>(
                                                  c => c.AccessToken.Equals(model.AccessToken) &&
                                                  c.OrganisationDateOfInception.Equals(model.OrganisationDateOfInception) &&
                                                  c.OrganisationName.Equals(model.OrganisationName) &&
                                                  c.OrganisationReferenceNumber.Equals(model.OrganisationReferenceNumber) &&
                                                  c.OrganisationAddress.Equals(model.OrganisationAddress) &&
                                                  c.OrganisationDateOfInception.Equals(model.OrganisationDateOfInception) &&
                                                  c.OrganisationStatus.Equals(model.OrganisationStatus) &&
                                                  c.PayeReference.Equals(model.PayeReference) &&
                                                  c.AccessToken.Equals(model.AccessToken) &&
                                                  c.RefreshToken.Equals(model.RefreshToken) &&
                                                  c.EmployerRefName.Equals(model.EmployerRefName)
                                                  )));
        }