예제 #1
0
        public async Task ShouldSuccessIfBankAuthorizeAsync()
        {
            var bank = new Mock <IBankClient>();
            var repo = new Mock <IPaymentRepository>();

            var request = ValidPaymentRequest.Create(new PaymentRequest(
                                                         cardNumber: "0000-0000-0000-0000",
                                                         expiry: new DateTimeOffset(2020, 01, 01, 0, 0, 0, TimeSpan.Zero),
                                                         amount: 100,
                                                         currency: "USD",
                                                         cvv: "000")).Value;

            var bankRequest = new BankRequest("data");

            bank.Setup(m => m.CreateBankRequestAsync(
                           It.Is <ValidPaymentRequest>(d => d.CardNumber == request.CardNumber)))
            .ReturnsAsync(bankRequest);

            bank.Setup(m => m.AuthorizeAsync(
                           It.Is <BankRequest>(r => r.Data == bankRequest.Data)))
            .ReturnsAsync(Result <BankAuthorizationId> .CreateSuccess(new BankAuthorizationId("Id")));

            var sut    = new PaymentProcessing(bank.Object, repo.Object);
            var actual = await sut.ProcessAsync(request);

            Assert.True(actual.IsSuccess);
        }
예제 #2
0
        public async Task <JsonResult> Post(PaymentRequest request)
        {
            var validationResult = ValidPaymentRequest.Create(request);

            var response = !validationResult.IsSuccess
                ? new PaymentResponse(validationResult.Errors)
                : new PaymentResponse(await _paymentProcessing.ProcessAsync(validationResult.Value));

            return(new JsonResult(response));
        }