private void EnsureRequestIsValid(PausePaymentsRequest request)
 {
     if (request.Action == PausePaymentsAction.NotSet)
     {
         throw new ArgumentException("Action is not set or invalid", nameof(request.Action));
     }
     if (request.AccountLegalEntityId == default)
     {
         throw new ArgumentException("AccountLegalEntityId is not set", nameof(request.AccountLegalEntityId));
     }
     if (request.ULN == default)
     {
         throw new ArgumentException("ULN is not set", nameof(request.ULN));
     }
     if (request.ServiceRequest == null)
     {
         throw new ArgumentException("Service Request is not set", nameof(request.ServiceRequest));
     }
     if (string.IsNullOrWhiteSpace(request.ServiceRequest.TaskId))
     {
         throw new ArgumentException("Service Request Task Id is not set", nameof(request.ServiceRequest.TaskId));
     }
     if (string.IsNullOrWhiteSpace(request.ServiceRequest.DecisionReference))
     {
         throw new ArgumentException("Service Request Decision Reference is not set", nameof(request.ServiceRequest.DecisionReference));
     }
     if (request.ServiceRequest.TaskCreatedDate == null)
     {
         throw new ArgumentException("Service Request Task Created Date is not set", nameof(request.ServiceRequest.TaskCreatedDate));
     }
 }
Beispiel #2
0
        public async Task WhenThePausePaymentsRequestIsSent()
        {
            _pausePaymentsRequest = _fixture.Build <PausePaymentsRequest>()
                                    .With(r => r.Action, PausePaymentsAction.Pause)
                                    .With(r => r.AccountLegalEntityId, _application.AccountLegalEntityId)
                                    .With(r => r.ULN, _apprenticeship.ULN)
                                    .Create();

            var url = "pause-payments";

            _response = await EmployerIncentiveApi.Post(url, _pausePaymentsRequest);
        }
 public SetPausePaymentsSteps(TestContext testContext) : base(testContext)
 {
     _testContext         = testContext;
     _fixture             = new Fixture();
     _pausePaymentRequest = new PausePaymentsRequest
     {
         Action = PausePaymentsAction.NotSet,
         AccountLegalEntityId = _fixture.Create <long>(),
         ULN            = _fixture.Create <long>(),
         ServiceRequest = _fixture.Create <ServiceRequest>()
     };
 }
Beispiel #4
0
        public async Task WhenAnInvalidRequestIsSent()
        {
            _pausePaymentsRequest = _fixture.Build <PausePaymentsRequest>()
                                    .With(r => r.Action, PausePaymentsAction.Resume)
                                    .With(r => r.AccountLegalEntityId, 0)
                                    .With(r => r.ULN, 0)
                                    .Create();

            var url = "pause-payments";

            _response = await EmployerIncentiveApi.Post(url, _pausePaymentsRequest);
        }
        public async Task SetPauseStatus(PausePaymentsRequest request)
        {
            EnsureRequestIsValid(request);

            var response = await _client.PostAsJsonAsync("pause-payments", request);

            if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.BadRequest)
            {
                throw new PausePaymentServiceException(response.StatusCode, await GetContentAsString(response));
            }

            response.EnsureSuccessStatusCode();
        }
        public async Task <IActionResult> PausePayments([FromBody] PausePaymentsRequest request)
        {
            try
            {
                await _mediator.Send(new PausePaymentsCommand(request), CancellationToken.None);

                return(Ok());
            }
            catch (HttpRequestContentException e)
            {
                var response = BuildErrorResponse(e);
                if (response != null)
                {
                    return(response);
                }
                throw;
            }
        }
        public async Task <IActionResult> PausePayments([FromBody] PausePaymentsRequest request)
        {
            try
            {
                await _commandDispatcher.Send(new PausePaymentsCommand(request.ULN, request.AccountLegalEntityId, request.ServiceRequest?.TaskId, request.ServiceRequest?.DecisionReference, request.ServiceRequest?.TaskCreatedDate, request.Action));

                return(new OkObjectResult(new { Message = $"Payments have been successfully {request.Action}d" }));
            }
            catch (InvalidRequestException e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
            catch (KeyNotFoundException e)
            {
                return(new NotFoundObjectResult(new { e.Message }));
            }
            catch (PausePaymentsException e)
            {
                return(new BadRequestObjectResult(new { e.Message }));
            }
        }
Beispiel #8
0
 public PausePaymentsCommand(PausePaymentsRequest pausePaymentsRequest)
 {
     PausePaymentsRequest = pausePaymentsRequest;
 }