Example #1
0
        public async Task ClosePledge_Returns_NotFound(
            int pledgeId,
            SetClosePledgeRequest closePledgeRequest,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] PledgeController pledgeController)
        {
            var closePledgeResult = new ClosePledgeCommandResult
            {
                ErrorContent = string.Empty,
                StatusCode   = HttpStatusCode.NotFound
            };

            mockMediator
            .Setup(x => x.Send(
                       It.Is <ClosePledgeCommand>((x) => x.PledgeId == pledgeId),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(closePledgeResult);

            var controllerResponse = await pledgeController.ClosePledge(pledgeId, closePledgeRequest);

            var statusResult = controllerResponse as StatusCodeResult;

            Assert.IsNotNull(statusResult);
            Assert.AreEqual((int)HttpStatusCode.NotFound, statusResult.StatusCode);
        }
Example #2
0
        public async Task ClosePledge_Returns_Error(
            int pledgeId,
            SetClosePledgeRequest closePledgeRequest,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] PledgeController pledgeController)
        {
            mockMediator
            .Setup(x => x.Send(
                       It.Is <ClosePledgeCommand>((x) => x.PledgeId == pledgeId),
                       It.IsAny <CancellationToken>()))
            .Throws(new InvalidOperationException());

            var controllerResponse = await pledgeController.ClosePledge(pledgeId, closePledgeRequest);

            var exception = controllerResponse as StatusCodeResult;

            Assert.IsNotNull(exception);
            Assert.AreEqual((int)HttpStatusCode.InternalServerError, exception.StatusCode);
        }
        public async Task <IActionResult> ClosePledge(int pledgeId, [FromBody] SetClosePledgeRequest request)
        {
            try
            {
                var result = await _mediator.Send(new ClosePledgeCommand
                {
                    PledgeId        = pledgeId,
                    UserId          = request.UserId,
                    UserDisplayName = request.UserDisplayName
                });

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    return(NotFound());
                }

                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error attempting to close a pledge");
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));
            }
        }