public async Task Pledge_Is_Closed_Unsuccessfull()
        {
            var error       = _fixture.Create <InvalidOperationException>();
            var apiResponse = new ApiResponse <ClosePledgeRequest>(new ClosePledgeRequest(_command.PledgeId,
                                                                                          new ClosePledgeRequest.ClosePledgeRequestData()), HttpStatusCode.NotFound, error.Message);

            _levyTransferMatchingService.Setup(x => x.ClosePledge(It.IsAny <ClosePledgeRequest>()))
            .Callback <ClosePledgeRequest>(r => _request = r)
            .ReturnsAsync(apiResponse);

            var response = await _handler.Handle(_command, CancellationToken.None);

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.AreEqual(error.Message, response.ErrorContent);
        }
        public void Setup()
        {
            _command = _fixture.Create <ClosePledgeCommand>();

            var apiResponse = new ApiResponse <ClosePledgeRequest>(new ClosePledgeRequest(_command.PledgeId,
                                                                                          new ClosePledgeRequest.ClosePledgeRequestData()), HttpStatusCode.OK, string.Empty);

            _levyTransferMatchingService = new Mock <ILevyTransferMatchingService>();

            _levyTransferMatchingService.Setup(x => x.ClosePledge(It.IsAny <ClosePledgeRequest>()))
            .Callback <ClosePledgeRequest>(r => _request = r)
            .ReturnsAsync(apiResponse);

            _handler = new ClosePledgeCommandHandler(_levyTransferMatchingService.Object, Mock.Of <ILogger <ClosePledgeCommandHandler> >());
        }
        public async Task <ClosePledgeCommandResult> Handle(ClosePledgeCommand request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Closing pledge {request.PledgeId}");

            var apiRequestData = new ClosePledgeRequestData
            {
                UserDisplayName = request.UserDisplayName,
                UserId          = request.UserId
            };

            var apiRequest = new ClosePledgeRequest(request.PledgeId, apiRequestData);

            var response = await _levyTransferMatchingService.ClosePledge(apiRequest);

            return(new ClosePledgeCommandResult
            {
                ErrorContent = response.ErrorContent,
                StatusCode = response.StatusCode
            });
        }
 public async Task <ApiResponse <ClosePledgeRequest> > ClosePledge(ClosePledgeRequest request)
 {
     return(await _levyTransferMatchingApiClient.PostWithResponseCode <ClosePledgeRequest>(request));
 }