Exemple #1
0
        public async Task <ServiceResult <Payment> > SetStatusAccepted(SetPaymentStatusAcceptedCommand command)
        {
            var validator        = _validator.GetValidator <SetPaymentStatusAcceptedCommand>();
            var validationResult = await validator.ValidateAsync(command);

            if (validationResult.IsValid == false)
            {
                _logger.LogError(
                    $"A validation error occurred while trying to set payment {command.Id} as accepted.");
                return(new ServiceResult <Payment>(ServiceErrorCode.ValidationError));
            }

            var payment = await _repository.Get(command.Id);

            if (payment == null)
            {
                _logger.LogError($"Payment with id {command.Id} not found.");
                return(new ServiceResult <Payment>(ServiceErrorCode.NotFound));
            }

            payment.Status = new PaymentStatus()
            {
                StatusCode = PaymentStatusCode.Accepted,
                Modified   = command.Modified
            };

            await _repository.Save(payment);

            return(new ServiceResult <Payment>(payment));
        }
Exemple #2
0
        public async Task SetPaymentStatusAccepted_NotFound_FailToSetPaymentAsSuccess()
        {
            // Arrange
            IsValidationSuccess(true);

            var paymentId = "TestId";

            var command = new SetPaymentStatusAcceptedCommand()
            {
                Id = paymentId
            };

            // Act
            var response = await _paymentService.SetStatusAccepted(command);

            // Assert
            Assert.IsTrue(response.IsError);
            Assert.AreEqual(response.Error.Code, ServiceErrorCode.NotFound);
        }
Exemple #3
0
        public async Task SetPaymentStatusAccepted_ValidRequest_SetsPaymentStatusAsAccepted()
        {
            // Arrange
            IsValidationSuccess(true);

            var paymentId = "TestId";

            var payment = new Payment()
            {
                Id              = paymentId,
                Amount          = 100,
                CardNumber      = "1111 0000 0000 0000",
                Currency        = "EUR",
                Cvv             = "123",
                ExpirationMonth = 10,
                ExpirationYear  = 20,
                Status          = new PaymentStatus()
                {
                    StatusCode = PaymentStatusCode.Processing
                }
            };

            var command = new SetPaymentStatusAcceptedCommand()
            {
                Id = paymentId
            };

            _repositoryMock.Setup(
                x => x.Get(paymentId))
            .ReturnsAsync(payment);

            // Act
            var response = await _paymentService.SetStatusAccepted(command);

            // Assert
            Assert.IsFalse(response.IsError);
            Assert.AreEqual(payment.Status.StatusCode, PaymentStatusCode.Accepted);
        }