public async Task <ServiceResult <Payment> > SetStatusRejected(SetPaymentStatusRejectedCommand command) { var validator = _validator.GetValidator <SetPaymentStatusRejectedCommand>(); var validationResult = await validator.ValidateAsync(command); if (validationResult.IsValid == false) { _logger.LogError( $"A validation error occurred while trying to set payment {command.Id} as rejected."); 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.Rejected, ErrorMessage = command.ErrorMessage, Modified = command.Modified }; await _repository.Save(payment); return(new ServiceResult <Payment>(payment)); }
public async Task SetPaymentStatusRejected_NotFound_FailToSetPaymentAsRejected() { // Arrange IsValidationSuccess(true); var paymentId = "TestId"; var command = new SetPaymentStatusRejectedCommand() { Id = paymentId }; // Act var response = await _paymentService.SetStatusRejected(command); // Assert Assert.IsTrue(response.IsError); Assert.AreEqual(response.Error.Code, ServiceErrorCode.NotFound); }
public async Task SetPaymentStatusRejected_ValidRequest_SetsPaymentStatusAsRejected() { // 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 SetPaymentStatusRejectedCommand() { Id = paymentId }; _repositoryMock.Setup( x => x.Get(paymentId)) .ReturnsAsync(payment); // Act var response = await _paymentService.SetStatusRejected(command); // Assert Assert.IsFalse(response.IsError); Assert.AreEqual(payment.Status.StatusCode, PaymentStatusCode.Rejected); }