Example #1
0
        public async Task <string> AssociateOrganisationWithContact(Guid contactId, EpaOrganisation org, string status, string actionChoice)
        {
            using (var connection = new SqlConnection(_configuration.SqlConnectionString))
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }


                connection.Execute(
                    "UPDATE [Contacts] SET [EndPointAssessorOrganisationId] = @OrganisationId, [OrganisationId] = @Id, " +
                    "[Status] = @status, [updatedAt] = getUtcDate() " +
                    "WHERE [Id] = @contactId ",
                    new { org.OrganisationId, org.Id, contactId, status });

                if (actionChoice == "MakePrimaryContact")
                {
                    connection.Execute("update o set PrimaryContact = c.Username from organisations o " +
                                       "inner join contacts c on o.EndPointAssessorOrganisationId = c.EndPointAssessorOrganisationId " +
                                       "Where c.id = @contactId",
                                       new { contactId });
                }

                return(contactId.ToString());
            }
        }
        public void Arrange()
        {
            _mediator = new Mock <IMediator>();
            _logger   = new Mock <ILogger <RegisterQueryController> >();
            // needs more details
            _assOrgDetails1 = new EpaOrganisation {
                OrganisationId = "Id1", Name = "Name 9", Ukprn = 9999999
            };
            _assOrgDetails2 = new EpaOrganisation {
                OrganisationId = "Id2", Name = "Name 2", Ukprn = 8888888
            };

            _expectedAssessmentOrganisationSetOfDetails = new List <EpaOrganisation>
            {
                _assOrgDetails1,
                _assOrgDetails2
            };

            _mediator.Setup(m =>
                            m.Send(It.IsAny <GetAssessmentOrganisationsbyStandardRequest>(),
                                   new CancellationToken())).ReturnsAsync(_expectedAssessmentOrganisationSetOfDetails);
            _queryController = new RegisterQueryController(_mediator.Object, _logger.Object);

            _result = _queryController.GetAssessmentOrganisationsByStandard(standardId).Result;
        }
Example #3
0
        private void SetupGetEpaoOrganisation()
        {
            _epaOrganisation = _autoFixture.Create <EpaOrganisation>();

            _mockApiClient.Setup(c => c.GetEpaOrganisation(It.IsAny <string>()))
            .ReturnsAsync(_epaOrganisation);
        }
Example #4
0
        public void Setup()
        {
            RegisterQueryRepository         = new Mock <IRegisterQueryRepository>();
            _assessmentOrganisationDetails1 = new EpaOrganisation {
                OrganisationId = "EPA9999", Name = "Name 100", Ukprn = 777777
            };
            _assessmentOrganisationDetails2 = new EpaOrganisation {
                OrganisationId = "EPA8888", Name = "Name 10"
            };
            _request = new GetAssessmentOrganisationsbyStandardRequest {
                StandardId = _standardId
            };

            Logger = new Mock <ILogger <GetAssessmentOrganisationsByStandardHandler> >();

            _expectedOrganisationListOfDetails = new List <EpaOrganisation>
            {
                _assessmentOrganisationDetails1,
                _assessmentOrganisationDetails2
            };

            RegisterQueryRepository.Setup(r => r.GetAssessmentOrganisationsByStandardId(_standardId))
            .Returns(Task.FromResult(_expectedOrganisationListOfDetails.AsEnumerable()));

            GetAssessmentOrganisationsByStandardHandler = new GetAssessmentOrganisationsByStandardHandler(RegisterQueryRepository.Object, Logger.Object);
        }
Example #5
0
        public void Setup()
        {
            _registerRepository      = new Mock <IRegisterRepository>();
            _cleanserService         = new Mock <ISpecialCharacterCleanserService>();
            _logger                  = new Mock <ILogger <CreateEpaOrganisationHandler> >();
            _idGenerator             = new Mock <IEpaOrganisationIdGenerator>();
            _validator               = new Mock <IEpaOrganisationValidator>();
            _registerQueryRepository = new Mock <IRegisterQueryRepository>();
            _organisationId          = "EPA999";

            _requestNoIssues = BuildRequest("name 1", 123321);
            _expectedOrganisationNoIssues = BuildOrganisation(_requestNoIssues, _organisationId);

            _registerRepository.Setup(r => r.CreateEpaOrganisation(It.IsAny <EpaOrganisation>()))
            .Returns(Task.FromResult(_expectedOrganisationNoIssues.OrganisationId));
            _registerQueryRepository.Setup(x => x.GetEpaOrgIdByEndPointAssessmentName(It.IsAny <string>())).Returns(Task.FromResult("EPA0001"));

            _cleanserService.Setup(c => c.CleanseStringForSpecialCharacters(It.IsAny <string>()))
            .Returns((string s) => s);

            var validationResponse = new ValidationResponse();

            _validator.Setup(x => x.ValidatorCreateEpaOrganisationRequest(It.IsAny <CreateEpaOrganisationRequest>()))
            .Returns(validationResponse);

            _createEpaOrganisationHandler = new CreateEpaOrganisationHandler(_registerRepository.Object, _registerQueryRepository.Object, _idGenerator.Object, _logger.Object, _cleanserService.Object, _validator.Object);
        }
Example #6
0
        public void Arrange()
        {
            _mockStandardService         = new Mock <IStandardService>();
            _mockRegisterQueryRepository = new Mock <IRegisterQueryRepository>();

            var fixture = new Fixture();

            var organisationStandardResponse = fixture.Build <OrganisationStandard>().Create();

            _organisationResponse = fixture.Create <EpaOrganisation>();
            _standardResponse     = fixture.Create <Standard>();

            _versions = fixture.Create <IEnumerable <OrganisationStandardVersion> >();

            _mockRegisterQueryRepository.Setup(r => r.GetOrganisationStandardFromOrganisationStandardId(It.IsAny <int>()))
            .ReturnsAsync(organisationStandardResponse);

            _mockRegisterQueryRepository.Setup(r => r.GetEpaOrganisationByOrganisationId(organisationStandardResponse.OrganisationId))
            .ReturnsAsync(_organisationResponse);

            _mockStandardService.Setup(ss => ss.GetStandardVersionById(organisationStandardResponse.IFateReferenceNumber, It.IsAny <string>()))
            .ReturnsAsync(_standardResponse);

            _mockStandardService.Setup(ss => ss.GetEPAORegisteredStandardVersions(_organisationResponse.OrganisationId, _standardResponse.LarsCode))
            .ReturnsAsync(_versions);

            _handler = new GetOrganisationStandardHandler(_mockRegisterQueryRepository.Object, Mock.Of <ILogger <GetAssessmentOrganisationHandler> >(), _mockStandardService.Object);
        }
        public void Arrange()
        {
            _mediator       = new Mock <IMediator>();
            _logger         = new Mock <ILogger <RegisterController> >();
            _organisationId = "EPA999";

            _request = new CreateEpaOrganisationRequest
            {
                Name  = "name 1",
                Ukprn = 123321,
                OrganisationTypeId = 5,
                LegalName          = "legal name 1",
                TradingName        = "name 1",
                WebsiteLink        = "website link 1",
                Address1           = "address 1",
                Address2           = "address 2",
                Address3           = "address 3",
                Address4           = "address 4",
                Postcode           = "postcode",
                CompanyNumber      = "company number",
                CharityNumber      = "charity number"
            };

            _returnedOrganisation = new EpaOrganisation
            {
                Id                 = Guid.NewGuid(),
                CreatedAt          = DateTime.Now,
                Name               = _request.Name,
                OrganisationId     = _organisationId,
                Ukprn              = _request.Ukprn,
                PrimaryContact     = null,
                PrimaryContactName = null,
                Status             = OrganisationStatus.New,
                OrganisationTypeId = _request.OrganisationTypeId,
                OrganisationData   = new OrganisationData
                {
                    LegalName     = _request.LegalName,
                    TradingName   = _request.TradingName,
                    Address1      = _request.Address1,
                    Address2      = _request.Address2,
                    Address3      = _request.Address3,
                    Address4      = _request.Address4,
                    Postcode      = _request.Postcode,
                    CompanyNumber = _request.CompanyNumber,
                    CharityNumber = _request.CharityNumber
                }
            };

            _mediator.Setup(m =>
                            m.Send(_request, new CancellationToken())).Throws <AlreadyExistsException>();

            _controller = new RegisterController(_mediator.Object, _logger.Object);
            _result     = _controller.CreateOrganisation(_request).Result;
        }
Example #8
0
        private static EpaOrganisation MapOrganisationRequestToOrganisation(CreateEpaOrganisationRequest request, string newOrganisationId)
        {
            if (!string.IsNullOrWhiteSpace(request.CompanyNumber))
            {
                request.CompanyNumber = request.CompanyNumber.ToUpper();
            }

            if (!string.IsNullOrWhiteSpace(request.CharityNumber))
            {
                request.CharityNumber = request.CharityNumber.ToUpper();
            }

            var organisation = new EpaOrganisation
            {
                Name               = request.Name.Trim(),
                OrganisationId     = newOrganisationId,
                OrganisationTypeId = request.OrganisationTypeId,
                Ukprn              = request.Ukprn,
                Status             = string.IsNullOrEmpty(request.Status) ? "New" : request.Status,
                Id = Guid.NewGuid(),
                OrganisationData = new OrganisationData
                {
                    Address1                  = request.Address1,
                    Address2                  = request.Address2,
                    Address3                  = request.Address3,
                    Address4                  = request.Address4,
                    Postcode                  = request.Postcode,
                    LegalName                 = request.LegalName,
                    TradingName               = request.TradingName,
                    ProviderName              = request.ProviderName,
                    Email                     = request.Email,
                    PhoneNumber               = request.PhoneNumber,
                    WebsiteLink               = request.WebsiteLink,
                    CompanyNumber             = request.CompanyNumber,
                    CompanySummary            = request.CompanySummary,
                    CharityNumber             = request.CharityNumber,
                    CharitySummary            = request.CharitySummary,
                    OrganisationReferenceType = request.OrganisationReferenceType,
                    OrganisationReferenceId   = request.OrganisationReferenceId,
                    RoATPApproved             = request.RoATPApproved,
                    RoEPAOApproved            = request.RoEPAOApproved,
                    EndPointAssessmentOrgId   = request.EndPointAssessmentOrgId,
                    FinancialGrades           = new List <ApplyTypes.FinancialGrade>(),
                    FHADetails                = new FHADetails
                    {
                        FinancialDueDate = request.FinancialDueDate,
                        FinancialExempt  = request.FinancialExempt
                    }
                }
            };

            return(organisation);
        }
Example #9
0
        public async Task <string> CreateEpaOrganisation(EpaOrganisation org)
        {
            var orgData = JsonConvert.SerializeObject(org.OrganisationData);
            await _unitOfWork.Connection.ExecuteAsync(
                "INSERT INTO [Organisations] ([Id],[CreatedAt],[EndPointAssessorName],[EndPointAssessorOrganisationId], " +
                "[EndPointAssessorUkprn],[Status],[OrganisationTypeId],[OrganisationData]) " +
                $@"VALUES (@id, GetUtcDate(), @name, @organisationId, @ukprn, @status, @organisationTypeId,  @orgData)",
                new { org.Id, org.Name, org.OrganisationId, org.Ukprn, org.Status, org.OrganisationTypeId, orgData }
                );

            return(org.OrganisationId);
        }
Example #10
0
        public async Task <string> UpdateEpaOrganisation(EpaOrganisation org)
        {
            var orgData = JsonConvert.SerializeObject(org.OrganisationData);
            await _unitOfWork.Connection.ExecuteAsync(
                "UPDATE [Organisations] SET [UpdatedAt] = GetUtcDate(), [EndPointAssessorName] = @Name, " +
                "[EndPointAssessorUkprn] = @ukprn, [OrganisationTypeId] = @organisationTypeId, " +
                "[OrganisationData] = @orgData, Status = @status WHERE [EndPointAssessorOrganisationId] = @organisationId",
                new { org.Name, org.Ukprn, org.OrganisationTypeId, orgData, org.Status, org.OrganisationId });

            _logger.LogInformation($"Updated EPAO Organisation {org.OrganisationId} with status = {org.Status}");

            return(org.OrganisationId);
        }
Example #11
0
        public static async Task SetFinancialReviewStatus(EpaOrganisation org, IRegisterQueryRepository registerQueryRepository)
        {
            if (null != org)
            {
                AssessorService.Api.Types.Models.AO.OrganisationType orgType = null;
                var orgTypes = await registerQueryRepository.GetOrganisationTypes();

                if (orgTypes != null)
                {
                    orgType = orgTypes.FirstOrDefault(x => x.Id == org.OrganisationTypeId);
                }

                org.FinancialReviewStatus = IsFinancialExempt(org.OrganisationData?.FHADetails?.FinancialExempt, org.OrganisationData?.FHADetails?.FinancialDueDate, orgType) ? ApplyTypes.FinancialReviewStatus.Exempt : ApplyTypes.FinancialReviewStatus.Required;
            }
        }
Example #12
0
        public void SetUpOrganisationTests()
        {
            _repository            = new RegisterRepository(_databaseService.WebConfiguration, new Mock <ILogger <RegisterRepository> >().Object);
            _validationRepository  = new RegisterValidationRepository(_databaseService.WebConfiguration);
            _queryRepository       = new RegisterQueryRepository(_databaseService.WebConfiguration);
            _organisationIdCreated = "EPA0987";
            _ukprnCreated          = 123321;
            var org2IdCreated = "EPA0001";

            _organisationTypeId = 5;
            OrganisationTypeHandler.InsertRecord(new OrganisationTypeModel {
                Id = _organisationTypeId, Status = "new", Type = "organisation type 1"
            });
            _id = Guid.NewGuid();

            _organisation = new EpaOrganisation
            {
                Id                 = _id,
                CreatedAt          = DateTime.Now,
                Name               = "name 2",
                OrganisationId     = _organisationIdCreated,
                Ukprn              = _ukprnCreated,
                PrimaryContact     = null,
                PrimaryContactName = null,
                Status             = OrganisationStatus.New,
                OrganisationTypeId = _organisationTypeId,
                OrganisationData   = new OrganisationData
                {
                    LegalName   = " legal name",
                    TradingName = "trading name",
                    Address1    = "address 1",
                    Address2    = "address 2",
                    Address3    = "address 3",
                    Address4    = "address 4",
                    Postcode    = "postcode"
                }
            };

            _organisation2 = new EpaOrganisation
            {
                Id                 = Guid.NewGuid(),
                Name               = "name 1",
                OrganisationId     = org2IdCreated,
                Status             = OrganisationStatus.New,
                OrganisationTypeId = null
            };
        }
        public void Arrange()
        {
            _mediator = new Mock <IMediator>();
            _logger   = new Mock <ILogger <RegisterQueryController> >();
            _expectedAssessmentOrganisationDetails = new EpaOrganisation
            {
                OrganisationId = OrganisationId,
                Name           = "Organisation X",
                Ukprn          = 123456
            };


            _mediator.Setup(m =>
                            m.Send(It.IsAny <GetAssessmentOrganisationRequest>(),
                                   new CancellationToken())).ReturnsAsync(_expectedAssessmentOrganisationDetails);
            _queryController = new RegisterQueryController(_mediator.Object, _logger.Object);

            _result = _queryController.Head(OrganisationId).Result;
        }
Example #14
0
        public async Task <string> CreateEpaOrganisation(EpaOrganisation org)
        {
            using (var connection = new SqlConnection(_configuration.SqlConnectionString))
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }

                var orgData = JsonConvert.SerializeObject(org.OrganisationData);
                connection.Execute(
                    "INSERT INTO [Organisations] ([Id],[CreatedAt],[EndPointAssessorName],[EndPointAssessorOrganisationId], " +
                    "[EndPointAssessorUkprn],[Status],[OrganisationTypeId],[OrganisationData]) " +
                    $@"VALUES (@id, GetUtcDate(), @name, @organisationId, @ukprn, @status, @organisationTypeId,  @orgData)",
                    new { org.Id, org.Name, org.OrganisationId, org.Ukprn, org.Status, org.OrganisationTypeId, orgData }
                    );

                return(org.OrganisationId);
            }
        }
Example #15
0
        public async Task <IActionResult> Results(string searchString, int page = 1)
        {
            EpaOrganisation org           = null;
            var             searchResults = await _apiClient.Search(searchString, page);

            if (!string.IsNullOrEmpty(searchResults?.EndpointAssessorOrganisationId))
            {
                org = await _apiClient.GetEpaOrganisation(searchResults.EndpointAssessorOrganisationId);
            }

            var searchViewModel = new SearchViewModel
            {
                OrganisationName  = org?.Name ?? string.Empty,
                StaffSearchResult = searchResults,
                SearchString      = searchString,
                Page = page
            };

            return(View(searchViewModel));
        }
Example #16
0
        public void Setup()
        {
            _registerQueryRepository = new Mock <IRegisterQueryRepository>();
            _registerRepository      = new Mock <IRegisterRepository>();
            _cleanserService         = new Mock <ISpecialCharacterCleanserService>();
            _validator      = new Mock <IEpaOrganisationValidator>();
            _logger         = new Mock <ILogger <UpdateEpaOrganisationHandler> >();
            _organisationId = "EPA999";

            _requestNoIssues = BuildRequest("name 1", _organisationId, 123321);
            _expectedOrganisationNoIssues = BuildOrganisation(_requestNoIssues);

            _registerQueryRepository.Setup(rq => rq.GetEpaOrganisationByOrganisationId(_organisationId)).ReturnsAsync(new EpaOrganisation());
            _registerRepository.Setup(r => r.UpdateEpaOrganisation(It.IsAny <EpaOrganisation>()))
            .ReturnsAsync(_expectedOrganisationNoIssues.OrganisationId);

            _cleanserService.Setup(c => c.CleanseStringForSpecialCharacters(It.IsAny <string>()))
            .Returns((string s) => s);

            _updateEpaOrganisationHandler = new UpdateEpaOrganisationHandler(_registerQueryRepository.Object, _registerRepository.Object, _logger.Object, _cleanserService.Object, _validator.Object);
        }
Example #17
0
        public async Task <string> UpdateEpaOrganisation(EpaOrganisation org)
        {
            using (var connection = new SqlConnection(_configuration.SqlConnectionString))
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }

                var orgData = JsonConvert.SerializeObject(org.OrganisationData);

                connection.Execute(
                    "UPDATE [Organisations] SET [UpdatedAt] = GetUtcDate(), [EndPointAssessorName] = @Name, " +
                    "[EndPointAssessorUkprn] = @ukprn, [OrganisationTypeId] = @organisationTypeId, " +
                    "[OrganisationData] = @orgData, Status = @status WHERE [EndPointAssessorOrganisationId] = @organisationId",
                    new { org.Name, org.Ukprn, org.OrganisationTypeId, orgData, org.Status, org.OrganisationId });

                _logger.LogInformation($"Updated EPAO Organisation {org.OrganisationId} with status = {org.Status}");

                return(org.OrganisationId);
            }
        }
Example #18
0
        public void Setup()
        {
            RegisterQueryRepository = new Mock <IRegisterQueryRepository>();

            Logger = new Mock <ILogger <GetAssessmentOrganisationHandler> >();

            _requestDetails = new GetAssessmentOrganisationRequest {
                OrganisationId = OrganisationId
            };

            _initialOrganisationDetails = new EpaOrganisation
            {
                OrganisationId = OrganisationId,
                Name           = "Organisation X",
                Ukprn          = 123456
            };

            RegisterQueryRepository.Setup(r => r.GetEpaOrganisationByOrganisationId(OrganisationId))
            .Returns(Task.FromResult(_initialOrganisationDetails));

            GetAssessmentOrganisationDetailsHandler = new GetAssessmentOrganisationHandler(RegisterQueryRepository.Object, Logger.Object);
        }
        private ViewAndEditOrganisationViewModel MapOrganisationModel(EpaOrganisation organisation)
        {
            var viewModel = new ViewAndEditOrganisationViewModel
            {
                OrganisationId = organisation.OrganisationId,
                Email          = organisation.OrganisationData?.Email,
                PhoneNumber    = organisation.OrganisationData?.PhoneNumber,
                WebsiteLink    = organisation.OrganisationData?.WebsiteLink,
                Address1       = organisation.OrganisationData?.Address1,
                Address2       = organisation.OrganisationData?.Address2,
                Address3       = organisation.OrganisationData?.Address3,
                Address4       = organisation.OrganisationData?.Address4,
                Postcode       = organisation.OrganisationData?.Postcode,
                PrimaryContact = !string.IsNullOrEmpty(organisation.PrimaryContact)
                    ? organisation.PrimaryContact
                    : string.Empty,
                PrimaryContactName = !string.IsNullOrEmpty(organisation.PrimaryContactName)
                    ? organisation.PrimaryContactName
                    : string.Empty
            };

            return(viewModel);
        }
Example #20
0
        public ConfirmEpaoViewModel(EpaOrganisation epao, string mergeOrganisationType, string searchString)
        {
            Name                = epao.Name;
            EpaoId              = epao.OrganisationId;
            PrimaryContactName  = epao.PrimaryContactName;
            PrimaryContactEmail = epao.PrimaryContact;
            Ukprn               = epao.Ukprn;
            LegalName           = epao.OrganisationData.LegalName;
            OrganisationType    = epao.OrganisationData.OrganisationReferenceType;
            TradingName         = epao.OrganisationData.TradingName;
            CompanyNumber       = epao.OrganisationData.CompanyNumber;
            Email               = epao.OrganisationData.Email;
            PhoneNumber         = epao.OrganisationData.PhoneNumber;
            Website             = epao.OrganisationData.WebsiteLink;
            Address1            = epao.OrganisationData.Address1;
            Address2            = epao.OrganisationData.Address2;
            Address3            = epao.OrganisationData.Address3;
            Address4            = epao.OrganisationData.Address4;
            City                = epao.OrganisationData.City;
            Postcode            = epao.OrganisationData.Postcode;

            MergeOrganisationType = mergeOrganisationType.ToLower();
            BackRouteSearchString = searchString;
        }
Example #21
0
        private async Task <RegisterViewAndEditOrganisationViewModel> MapOrganisationModel(EpaOrganisation organisation, bool pageStandards)
        {
            var notSetDescription = "Not set";
            var viewModel         = new RegisterViewAndEditOrganisationViewModel
            {
                Id                 = organisation.Id,
                OrganisationId     = organisation.OrganisationId,
                Name               = organisation.Name,
                Ukprn              = organisation.Ukprn,
                OrganisationTypeId = organisation.OrganisationTypeId,
                OrganisationType   = notSetDescription,
                LegalName          = organisation.OrganisationData?.LegalName,
                TradingName        = organisation.OrganisationData?.TradingName,
                Email              = organisation.OrganisationData?.Email,
                PhoneNumber        = organisation.OrganisationData?.PhoneNumber,
                WebsiteLink        = organisation.OrganisationData?.WebsiteLink,
                Address1           = organisation.OrganisationData?.Address1,
                Address2           = organisation.OrganisationData?.Address2,
                Address3           = organisation.OrganisationData?.Address3,
                Address4           = organisation.OrganisationData?.Address4,
                Postcode           = organisation.OrganisationData?.Postcode,
                PrimaryContact     = organisation.PrimaryContact,
                PrimaryContactName = organisation.PrimaryContactName ?? notSetDescription,
                CharityNumber      = organisation.OrganisationData?.CharityNumber,
                CompanyNumber      = organisation.OrganisationData?.CompanyNumber,
                Status             = organisation.Status,
                FinancialDueDate   = organisation.OrganisationData?.FHADetails?.FinancialDueDate,
                FinancialExempt    = organisation.OrganisationData?.FHADetails?.FinancialExempt
            };

            viewModel.OrganisationTypes = _apiClient.GetOrganisationTypes().Result;

            if (viewModel.OrganisationTypeId != null)
            {
                var organisationTypes = viewModel.OrganisationTypes;
                viewModel.OrganisationType = organisationTypes.FirstOrDefault(x => x.Id == viewModel.OrganisationTypeId)?.Type;
            }

            await GatherOrganisationContacts(viewModel);
            await GatherOrganisationStandards(viewModel, pageStandards);

            return(viewModel);
        }
Example #22
0
        private RegisterViewAndEditContactViewModel MapContactModel(AssessmentOrganisationContact contact, EpaOrganisation organisation)
        {
            var viewModel = new RegisterViewAndEditContactViewModel
            {
                Email            = contact.Email,
                ContactId        = contact.Id.ToString(),
                PhoneNumber      = contact.PhoneNumber,
                FirstName        = contact.FirstName,
                LastName         = contact.LastName,
                OrganisationName = organisation.Name,
                OrganisationId   = organisation.OrganisationId,
                IsPrimaryContact = contact.IsPrimaryContact
            };

            return(viewModel);
        }
        private static EpaOrganisation MapOrganisationRequestToOrganisation(UpdateEpaOrganisationRequest request, EpaOrganisation existingOrganisation)
        {
            var roEPAOApproved = existingOrganisation?.OrganisationData?.RoEPAOApproved ?? false;

            var status = request.Status ?? existingOrganisation?.Status;

            if (status == "New" && request.ActionChoice == "MakeLive")
            {
                status         = "Live";
                roEPAOApproved = true;
            }
            else if (status == "New" && request.ActionChoice == "ApproveApplication")
            {
                status         = "New";
                roEPAOApproved = true;
            }
            else if (status == "Applying" && request.ActionChoice == "ApproveApplication")
            {
                roEPAOApproved = true;
            }

            if (!string.IsNullOrWhiteSpace(request.CompanyNumber))
            {
                request.CompanyNumber = request.CompanyNumber.ToUpper();
            }

            if (!string.IsNullOrWhiteSpace(request.CharityNumber))
            {
                request.CharityNumber = request.CharityNumber.ToUpper();
            }

            var organisation = new EpaOrganisation
            {
                Id                 = existingOrganisation?.Id ?? Guid.Empty,
                Name               = request.Name.Trim(),
                OrganisationId     = request.OrganisationId.Trim(),
                OrganisationTypeId = request.OrganisationTypeId,
                Ukprn              = request.Ukprn,
                Status             = status,
                OrganisationData   = new OrganisationData
                {
                    Address1                  = request.Address1,
                    Address2                  = request.Address2,
                    Address3                  = request.Address3,
                    Address4                  = request.Address4,
                    Postcode                  = request.Postcode,
                    LegalName                 = request.LegalName,
                    TradingName               = request.TradingName,
                    ProviderName              = request.ProviderName,
                    Email                     = request.Email,
                    PhoneNumber               = request.PhoneNumber,
                    WebsiteLink               = request.WebsiteLink,
                    CompanyNumber             = request.CompanyNumber,
                    CompanySummary            = request.CompanySummary ?? existingOrganisation?.OrganisationData?.CompanySummary,
                    CharityNumber             = request.CharityNumber,
                    CharitySummary            = request.CharitySummary ?? existingOrganisation?.OrganisationData?.CharitySummary,
                    OrganisationReferenceType = existingOrganisation?.OrganisationData?.OrganisationReferenceType,
                    OrganisationReferenceId   = existingOrganisation?.OrganisationData?.OrganisationReferenceId,
                    RoATPApproved             = existingOrganisation?.OrganisationData?.RoATPApproved ?? false,
                    RoEPAOApproved            = roEPAOApproved,
                    EndPointAssessmentOrgId   = existingOrganisation?.OrganisationData?.EndPointAssessmentOrgId,
                    FinancialGrades           = existingOrganisation?.OrganisationData?.FinancialGrades ?? new List <ApplyTypes.FinancialGrade>(),
                    FHADetails                = new FHADetails
                    {
                        FinancialDueDate = request.FinancialDueDate,
                        FinancialExempt  = request.FinancialExempt
                    }
                }
            };

            return(organisation);
        }
Example #24
0
        public void SetUpOrganisationTests()
        {
            _repository               = new RegisterRepository(_databaseService.WebConfiguration, new Mock <ILogger <RegisterRepository> >().Object);
            _organisationIdCreated    = "EPA987";
            _ukprnBefore              = 123321;
            _ukprnAfter               = 124421;
            _organisationTypeIdBefore = 5;
            _organisationTypeIdAfter  = 6;
            _updatedAt = DateTime.Today.Date.AddHours(9);
            OrganisationTypeHandler.InsertRecord(new OrganisationTypeModel {
                Id = _organisationTypeIdBefore, Status = "new", Type = "organisation type 1"
            });
            OrganisationTypeHandler.InsertRecord(new OrganisationTypeModel {
                Id = _organisationTypeIdAfter, Status = "new", Type = "organisation type 2"
            });
            _nameUpdated = "name 2";
            _createdAt   = DateTime.Today.Date.AddHours(8);

            _initialOrganisationDetails = new EpaOrganisation
            {
                Id                 = Guid.NewGuid(),
                CreatedAt          = _createdAt,
                Name               = "name 1",
                OrganisationId     = _organisationIdCreated,
                Ukprn              = _ukprnBefore,
                PrimaryContact     = null,
                PrimaryContactName = null,
                Status             = OrganisationStatus.New,
                OrganisationTypeId = _organisationTypeIdBefore,
                OrganisationData   = new OrganisationData
                {
                    LegalName   = " legal name",
                    TradingName = "trading name",
                    Address1    = "address 1",
                    Address2    = "address 2",
                    Address3    = "address 3",
                    Address4    = "address 4",
                    Postcode    = "postcode"
                }
            };

            _updatedOrgData = new OrganisationData
            {
                LegalName   = " legal name 2",
                TradingName = "trading name 2",
                Address1    = "address 1b",
                Address2    = "address 2b",
                Address3    = "address 3b",
                Address4    = "address 4b",
                Postcode    = "postcodeb"
            };

            _expectedOrganisationDetails = new EpaOrganisation
            {
                Id                 = _initialOrganisationDetails.Id,
                CreatedAt          = _createdAt,
                Name               = _nameUpdated,
                OrganisationId     = _organisationIdCreated,
                Ukprn              = _ukprnAfter,
                PrimaryContact     = null,
                PrimaryContactName = null,
                Status             = OrganisationStatus.New,
                UpdatedAt          = _updatedAt,
                OrganisationTypeId = _organisationTypeIdAfter,
                OrganisationData   = _updatedOrgData
            };
        }
        public void Arrange()
        {
            EpaOrganisation = new EpaOrganisation
            {
                Id             = Guid.NewGuid(),
                OrganisationId = "EPA0001"
            };

            _eMailTemplate = new EMailTemplate
            {
                TemplateName = "EmailTemplate"
            };

            _eMailTemplateQueryRepository = new Mock <IEMailTemplateQueryRepository>();
            _eMailTemplateQueryRepository.Setup(c => c.GetEmailTemplate(It.IsAny <string>()))
            .ReturnsAsync(_eMailTemplate);

            _mediator = new Mock <IMediator>();

            _mediator.Setup(c => c.Send(
                                It.Is <GetAssessmentOrganisationRequest>(p => p.OrganisationId == EpaOrganisation.OrganisationId),
                                It.IsAny <CancellationToken>()))
            .ReturnsAsync(EpaOrganisation);

            _firstLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "First Live Person",
                    Status      = ContactStatus.Live
                }
            };
            _firstLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ChangeOrganisationDetailsContactsPrivilege.Privilege.Key
            });

            _secondLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "Second Live Person",
                    GivenNames  = "Second Live",
                    Status      = ContactStatus.Live
                }
            };
            _secondLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ChangeOrganisationDetailsContactsPrivilege.Privilege.Key
            });
            _secondLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _thirdLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "thirdliveorganisation.com",
                    DisplayName = "Third Live Person",
                    GivenNames  = "Third Live",
                    Status      = ContactStatus.Live
                }
            };
            _thirdLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _firstPendingContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "First Pending Person",
                    GivenNames  = "First Pending",
                    Status      = ContactStatus.InvitePending
                }
            };
            _firstPendingContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _mediator.Setup(c => c.Send(
                                It.IsAny <GetAllContactsIncludePrivilegesRequest>(),
                                It.IsAny <CancellationToken>())
                            )
            .ReturnsAsync(new List <ContactIncludePrivilegesResponse>
            {
                _firstLiveContact,
                _secondLiveContact,
                _thirdLiveContact,
                _firstPendingContact
            });

            EditorCommon = _thirdLiveContact.Contact.DisplayName;

            _logger = new Mock <ILogger <SendOrganisationDetailsAmendedEmailHandler> >();

            // this callback is being used to capture the send email requests which are later
            // compared; this is done like this due to the anonymous object for Tokens
            // which cannot be verified in the normal style - NOTE: also the
            // Returns(Task.CompletedTask) which is necessary for a null returning async
            // Mock which is handled by a callback to avoid a NullReferenceException
            // during testing
            _emailRequestsSent = new List <string>();
            _mediator
            .Setup(c =>
                   c.Send(
                       It.IsAny <SendEmailRequest>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Unit())
            .Callback <IRequest, CancellationToken>((request, token) =>
            {
                var sendEmailRequest = request as SendEmailRequest;
                _emailRequestsSent.Add(JsonConvert.SerializeObject(new
                {
                    sendEmailRequest.Email,
                    EmailTemplate = sendEmailRequest.EmailTemplate.TemplateName,
                    sendEmailRequest.Tokens
                }));
            });

            _sut = new SendOrganisationDetailsAmendedEmailHandler(
                _eMailTemplateQueryRepository.Object, _mediator.Object, _logger.Object);
        }
        public void Arrange(bool addEpaoClaim, bool addUkprnClaim, List <ContactsPrivilege> contactsPrivileges = null)
        {
            HttpContextAssessor = new Mock <IHttpContextAccessor>();

            Logger         = new Mock <ILogger <OrganisationController> >();
            SessionService = new Mock <ISessionService>();
            TokenService   = new Mock <ITokenService>();
            TokenService.Setup(s => s.GetToken()).Returns("jwt");

            OrganisationApiClient = new Mock <IOrganisationsApiClient>();
            OrganisationApiClient.Setup(c => c.Get("12345")).ReturnsAsync(new OrganisationResponse()
            {
            });

            EpaOrganisation = new EpaOrganisation
            {
                Id               = OrganisationOneId,
                OrganisationId   = EpaoId,
                OrganisationData = new OrganisationData
                {
                    Address1    = ValidAddress1,
                    Address2    = ValidAddress2,
                    Address3    = ValidAddress3,
                    Address4    = ValidAddress4,
                    Postcode    = ValidPostcode,
                    PhoneNumber = ValidPhoneNumber,
                    Email       = ValidEmailAddress,
                    WebsiteLink = ValidWebsiteLink
                },
                PrimaryContact = ValidPrimaryContact
            };

            OrganisationApiClient.Setup(c => c.GetEpaOrganisation(EpaoId)).ReturnsAsync(EpaOrganisation);

            WebConfiguration = new Mock <IWebConfiguration>();
            WebConfiguration.Setup(c => c.AzureApiAuthentication).Returns(new AzureApiAuthentication
            {
                ProductId = "1234567"
            });

            ExternalApiClient = new Mock <IAzureApiClient>();
            ExternalApiClient.Setup(c => c.GetUserDetailsByUkprn(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())).ReturnsAsync(
                new List <AzureUser>
            {
                new AzureUser
                {
                    Subscriptions = new List <AzureSubscription>
                    {
                        new AzureSubscription()
                    }
                }
            });

            ContactsApiClient = new Mock <IContactsApiClient>();
            ContactsApiClient.Setup(c => c.GetPrivileges()).ReturnsAsync(
                new List <Privilege>()
            {
                new Privilege
                {
                    Id  = ChangeOrganisationPrivilegeId,
                    Key = Privileges.ChangeOrganisationDetails
                },
                new Privilege
                {
                    Id  = ManageUsersPrivilegeId,
                    Key = Privileges.ManageUsers
                }
            });

            ContactsApiClient.Setup(c => c.GetContactPrivileges(UserId)).ReturnsAsync(
                contactsPrivileges);

            EmailApiClient    = new Mock <IEmailApiClient>();
            ValidateApiClient = new Mock <IValidationApiClient>();

            var claims = new List <Claim>();

            if (addEpaoClaim)
            {
                claims.Add(new Claim("http://schemas.portal.com/epaoid", EpaoId.ToString()));
            }

            if (addUkprnClaim)
            {
                claims.Add(new Claim("http://schemas.portal.com/ukprn", "12345"));
            }

            claims.Add(new Claim("UserId", UserId.ToString()));

            HttpContextAssessor
            .Setup(c => c.HttpContext)
            .Returns(new DefaultHttpContext()
            {
                User = new ClaimsPrincipal(new ClaimsIdentity(claims.ToArray()))
            });

            sut = new OrganisationController(HttpContextAssessor.Object, OrganisationApiClient.Object, ExternalApiClient.Object,
                                             ContactsApiClient.Object, EmailApiClient.Object, ValidateApiClient.Object,
                                             Logger.Object, WebConfiguration.Object);
        }
        public RegisterBase()
        {
            EpaOrganisation organisation = new EpaOrganisation
            {
                Id                 = OrganisationOneId,
                OrganisationId     = OrganisationOneOrganisationId,
                OrganisationTypeId = 1
            };

            List <OrganisationType> organisationTypes = new List <OrganisationType>
            {
                new OrganisationType
                {
                    Id = 1
                }
            };

            List <ContactResponse> contacts = new List <ContactResponse>
            {
                new ContactResponse {
                    Id = ContactOneId
                },
                new ContactResponse {
                    Id = ContactTwoId
                }
            };

            List <ContactIncludePrivilegesResponse> users = new List <ContactIncludePrivilegesResponse>
            {
                new ContactIncludePrivilegesResponse {
                    Contact = new ContactResponse {
                        Id = UserOneId
                    }
                },
                new ContactIncludePrivilegesResponse {
                    Contact = new ContactResponse {
                        Id = UserTwoId
                    }
                },
                new ContactIncludePrivilegesResponse {
                    Contact = new ContactResponse {
                        Id = UserThreeId
                    }
                },
            };

            List <ContactResponse> contactsWhoCanBePrimary = new List <ContactResponse>
            {
                new ContactResponse {
                    Id = ContactOneId
                },
                new ContactResponse {
                    Id = ContactTwoId
                },
                new ContactResponse {
                    Id = UserOneId
                },
                new ContactResponse {
                    Id = UserTwoId
                },
                new ContactResponse {
                    Id = UserThreeId
                }
            };

            List <OrganisationStandardSummary> organisationStandards = new List <OrganisationStandardSummary>();

            for (int standard = 0; standard < 20; standard++)
            {
                organisationStandards.Add(new OrganisationStandardSummary
                {
                    Id = standard,
                    StandardCollation = new StandardCollation
                    {
                        ReferenceNumber = string.Format("ST{0:4}", standard),
                        StandardId      = standard,
                        Title           = string.Format("{0} Gravyboat Maker", NumberToAlpha(standard / 10))
                    },
                    DateStandardApprovedOnRegister = DateTime.Now.AddDays(-100)
                });;
            }

            List <DeliveryArea> deliveryAreas = new List <DeliveryArea>
            {
                new DeliveryArea {
                    Id = 1
                }
            };

            var organisationStandard = new OrganisationStandard()
            {
                OrganisationId = OrganisationOneOrganisationId, Id = organisationStandardId
            };

            List <ApplicationSummaryItem> standardApplications = new List <ApplicationSummaryItem>
            {
                new ApplicationSummaryItem
                {
                    ApplicationId     = Guid.NewGuid(),
                    StandardReference = "ST0002",
                    StandardName      = "Senior Gravyboat Maker"
                }
            };

            PaginatedList <ApplicationSummaryItem> standardApplicationPaginatedList
                = new PaginatedList <ApplicationSummaryItem>(standardApplications, standardApplications.Count, 1, short.MaxValue, 6);

            int    itemsPerPage  = 10;
            int    pageIndex     = 1;
            string sortColumn    = OrganisationStandardSortColumn.StandardName;
            string sortDirection = SortOrder.Asc;

            ApprovedStandards = new Mock <IPagingState>();

            ApprovedStandards.SetupGet(s => s.ItemsPerPage).Returns(itemsPerPage);
            ApprovedStandards.SetupSet(p => p.ItemsPerPage = It.IsAny <int>()).Callback <int>(r =>
            {
                itemsPerPage = r;
                ApprovedStandards.SetupGet(s => s.ItemsPerPage).Returns(itemsPerPage);
            });

            ApprovedStandards.SetupGet(s => s.PageIndex).Returns(pageIndex);
            ApprovedStandards.SetupSet(p => p.PageIndex = It.IsAny <int>()).Callback <int>(r =>
            {
                pageIndex = r;
                ApprovedStandards.SetupGet(s => s.PageIndex).Returns(pageIndex);
            });

            ApprovedStandards.SetupGet(s => s.SortColumn).Returns(sortColumn);
            ApprovedStandards.SetupSet(p => p.SortColumn = It.IsAny <string>()).Callback <string>(r =>
            {
                sortColumn = r;
                ApprovedStandards.SetupGet(s => s.SortColumn).Returns(sortColumn);
            });

            ApprovedStandards.SetupGet(s => s.SortDirection).Returns(sortDirection);
            ApprovedStandards.SetupSet(p => p.SortDirection = It.IsAny <string>()).Callback <string>(r =>
            {
                sortDirection = r;
                ApprovedStandards.SetupGet(s => s.SortDirection).Returns(sortDirection);
            });

            ControllerSession = new Mock <IControllerSession>();
            ControllerSession.Setup(p => p.Register_SessionValid).Returns(true);
            ControllerSession.Setup(p => p.Register_ApprovedStandards).Returns(ApprovedStandards.Object);

            ApiClient = new Mock <IApiClient>();
            ApiClient.Setup(p => p.GetEpaOrganisation(OrganisationOneOrganisationId)).ReturnsAsync(organisation);
            ApiClient.Setup(p => p.GetOrganisationTypes()).ReturnsAsync(organisationTypes);
            ApiClient.Setup(p => p.GetEpaOrganisationStandards(OrganisationOneOrganisationId)).ReturnsAsync(organisationStandards);
            ApiClient.Setup(p => p.GetOrganisationStandard(organisationStandardId)).ReturnsAsync(organisationStandard);
            ApiClient.Setup(p => p.GetDeliveryAreas()).ReturnsAsync(deliveryAreas);

            ApplyApiClient = new Mock <IApplicationApiClient>();
            ApplyApiClient.Setup(p => p.GetStandardApplications(It.IsAny <StandardApplicationsRequest>())).ReturnsAsync(standardApplicationPaginatedList);

            ContactsApiClient = new Mock <IContactsApiClient>();
            ContactsApiClient.Setup(p => p.GetAllContactsForOrganisation(OrganisationOneOrganisationId, null)).ReturnsAsync(contacts);
            ContactsApiClient.Setup(p => p.GetAllContactsForOrganisation(OrganisationOneOrganisationId, false)).ReturnsAsync(contacts);
            ContactsApiClient.Setup(p => p.GetAllContactsForOrganisationIncludePrivileges(OrganisationOneOrganisationId, true)).ReturnsAsync(users);
            ContactsApiClient.Setup(p => p.GetAllContactsWhoCanBePrimaryForOrganisation(OrganisationOneOrganisationId)).ReturnsAsync(contactsWhoCanBePrimary);

            StandardServiceClient = new Mock <IStandardServiceClient>();
            Env = new Mock <IHostingEnvironment>();
        }