Ejemplo n.º 1
0
        public async Task <IActionResult> AddOrganisation(RegisterOrganisationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.OrganisationTypes = await _apiClient.GetOrganisationTypes();

                return(View(viewModel));
            }

            var addOrganisationRequest = new CreateEpaOrganisationRequest
            {
                Name  = viewModel.Name,
                Ukprn = viewModel.Ukprn,
                OrganisationTypeId = viewModel.OrganisationTypeId,
                LegalName          = viewModel.LegalName,
                TradingName        = viewModel.TradingName,
                Email         = viewModel.Email,
                PhoneNumber   = viewModel.PhoneNumber,
                WebsiteLink   = viewModel.WebsiteLink,
                Address1      = viewModel.Address1,
                Address2      = viewModel.Address2,
                Address3      = viewModel.Address3,
                Address4      = viewModel.Address4,
                Postcode      = viewModel.Postcode,
                CompanyNumber = viewModel.CompanyNumber,
                CharityNumber = viewModel.CharityNumber
            };

            var organisationId = await _apiClient.CreateEpaOrganisation(addOrganisationRequest);

            return(RedirectToAction("ViewOrganisation", "register", new { organisationId }));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateOrganisation([FromBody] CreateEpaOrganisationRequest request)
        {
            try
            {
                _logger.LogInformation("Creating new Organisation");
                var result = await _mediator.Send(request);

                return(Ok(new EpaOrganisationResponse(result)));
            }

            catch (AlreadyExistsException ex)
            {
                _logger.LogError($@"Record already exists for organisation [{ex.Message}]");
                return(Conflict(new EpaOrganisationResponse(ex.Message)));
            }
            catch (BadRequestException ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(new EpaOrganisationResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _logger.LogError($@"Bad request, Message: [{ex.Message}]");
                return(BadRequest());
            }
        }
Ejemplo n.º 4
0
 private EpaOrganisation BuildOrganisation(CreateEpaOrganisationRequest request, string organisationId)
 {
     return(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
         }
     });
 }
Ejemplo n.º 5
0
        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"
            };

            _mediator.Setup(m =>
                            m.Send(_request, new CancellationToken())).ReturnsAsync(_organisationId);

            _controller = new RegisterController(_mediator.Object, _logger.Object);
            _result     = _controller.CreateOrganisation(_request).Result;
        }
        public async Task <string> CreateEpaOrganisation(CreateEpaOrganisationRequest request)
        {
            var result =
                await Post <CreateEpaOrganisationRequest, EpaOrganisationResponse>("api/ao/assessment-organisations",
                                                                                   request);

            return(result.Details);
        }
 public async Task <EpaOrganisationResponse> CreateEpaOrganisation(CreateEpaOrganisationRequest epaoOrganisationModel)
 {
     using (var request = new HttpRequestMessage(HttpMethod.Post, $"/api/ao/assessment-organisations/"))
     {
         return(await PostPutRequestWithResponse <CreateEpaOrganisationRequest, EpaOrganisationResponse>(request,
                                                                                                         epaoOrganisationModel));
     }
 }
        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;
        }
Ejemplo n.º 9
0
        public void CheckOrganisationRequestValidationWhenThereAreNoIssues()
        {
            var request = new CreateEpaOrganisationRequest
            {
                Name = "test", Ukprn = null, OrganisationTypeId = 9
            };

            _registerRepository.Setup(r => r.OrganisationTypeExists(It.IsAny <int>()))
            .Returns(Task.FromResult(true));
            var result = _validator.ValidatorCreateEpaOrganisationRequest(request);

            Assert.AreEqual(0, result.Errors.Count);
        }
Ejemplo n.º 10
0
        public void CheckOrganisationRequestValidationWhenThereIsInvalidOrganisationTypeIdAndNoName()
        {
            var request = new CreateEpaOrganisationRequest
            {
                Name = "", Ukprn = null, OrganisationTypeId = 9
            };

            _registerRepository.Setup(r => r.OrganisationTypeExists(It.IsAny <int>()))
            .Returns(Task.FromResult(false));
            var result = _validator.ValidatorCreateEpaOrganisationRequest(request);

            Assert.AreEqual(2, result.Errors.Count(x => x.StatusCode == ValidationStatusCode.BadRequest.ToString()));
            Assert.AreEqual(1, result.Errors.Count(x => x.Field == "OrganisationTypeId"));
            Assert.AreEqual(1, result.Errors.Count(x => x.Field == "Name"));
        }
Ejemplo n.º 11
0
        public void CheckOrganisationRequestValidationWhenThereIsNoOrganisationTypeId()
        {
            var request = new CreateEpaOrganisationRequest
            {
                Name  = "test",
                Ukprn = null,
                OrganisationTypeId = null
            };

            _registerRepository.Setup(r => r.OrganisationTypeExists(It.IsAny <int>()))
            .Returns(Task.FromResult(false));
            var result = _validator.ValidatorCreateEpaOrganisationRequest(request);

            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual("OrganisationTypeId", result.Errors[0].Field);
        }
        public ValidationResponse ValidatorCreateEpaOrganisationRequest(CreateEpaOrganisationRequest request)
        {
            var validationResult = new ValidationResponse();

            RunValidationCheckAndAppendAnyError("Name", CheckOrganisationName(request.Name), validationResult, ValidationStatusCode.BadRequest);
            RunValidationCheckAndAppendAnyError("OrganisationTypeId", CheckOrganisationTypeExists(request.OrganisationTypeId), validationResult, ValidationStatusCode.BadRequest);
            RunValidationCheckAndAppendAnyError("Ukprn", CheckUkprnIsValid(request.Ukprn), validationResult, ValidationStatusCode.BadRequest);
            RunValidationCheckAndAppendAnyError("Name", CheckOrganisationNameNotUsed(request.Name), validationResult, ValidationStatusCode.AlreadyExists);
            RunValidationCheckAndAppendAnyError("Ukprn", CheckIfOrganisationUkprnExists(request.Ukprn), validationResult, ValidationStatusCode.AlreadyExists);
            RunValidationCheckAndAppendAnyError("CompanyNumber", CheckCompanyNumberIsValid(request.CompanyNumber), validationResult, ValidationStatusCode.BadRequest);
            RunValidationCheckAndAppendAnyError("CompanyNumber", CheckIfOrganisationCompanyNumberExists(request.CompanyNumber), validationResult, ValidationStatusCode.AlreadyExists);
            RunValidationCheckAndAppendAnyError("CharityNumber", CheckCharityNumberIsValid(request.CharityNumber), validationResult, ValidationStatusCode.BadRequest);
            RunValidationCheckAndAppendAnyError("CharityNumber", CheckIfOrganisationCharityNumberExists(request.CharityNumber), validationResult, ValidationStatusCode.AlreadyExists);

            return(validationResult);
        }
Ejemplo n.º 13
0
        public void CreateOrganisationFailsValidation()
        {
            var validationResponse = BuildErrorResponse("Message", ValidationStatusCode.BadRequest);

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

            CreateEpaOrganisationRequest request = BuildRequest("Name", 100001234);

            Task <string> createOperation = _createEpaOrganisationHandler.Handle(request, new CancellationToken());
            string        message;

            _registerRepository.Verify(r => r.CreateEpaOrganisation(It.IsAny <EpaOrganisation>()), Times.Never);

            Assert.Throws <AggregateException>(() => message = createOperation.Result);
        }
Ejemplo n.º 14
0
        public void CheckOrganisationRequestValidationWhenThereIsInvalidOrganisationTypeIdAndPresentUkprn()
        {
            var request = new CreateEpaOrganisationRequest
            {
                Name = "test", Ukprn = 12345678, OrganisationTypeId = 9
            };

            _registerRepository.Setup(r => r.OrganisationTypeExists(It.IsAny <int>()))
            .Returns(Task.FromResult(false));
            _registerRepository.Setup(r => r.EpaOrganisationExistsWithUkprn(It.IsAny <long>()))
            .Returns(Task.FromResult(true));
            var result = _validator.ValidatorCreateEpaOrganisationRequest(request);

            Assert.AreEqual(1, result.Errors.Count(x => x.StatusCode == ValidationStatusCode.BadRequest.ToString()));
            Assert.AreEqual(1, result.Errors.Count(x => x.StatusCode == ValidationStatusCode.AlreadyExists.ToString()));
            Assert.AreEqual(1, result.Errors.Count(x => x.Field == "OrganisationTypeId"));
            Assert.AreEqual(1, result.Errors.Count(x => x.Field == "Ukprn"));
        }
Ejemplo n.º 15
0
 private CreateEpaOrganisationValidationRequest MapToCreateEpaOrganisationValidateRequest(CreateEpaOrganisationRequest request)
 {
     return(new CreateEpaOrganisationValidationRequest
     {
         Name = request?.Name,
         Ukprn = request?.Ukprn,
         OrganisationTypeId = request?.OrganisationTypeId,
         CompanyNumber = request?.CompanyNumber,
         CharityNumber = request?.CharityNumber
     });
 }
Ejemplo n.º 16
0
        public async Task <ValidationResponse> ValidateNewOrganisationRequest(CreateEpaOrganisationRequest request)
        {
            var validationRequest = MapToCreateEpaOrganisationValidateRequest(request);

            return(await _apiClient.CreateOrganisationValidate(validationRequest));
        }