protected override void RegisterDependencies(IServiceCollection collection)
        {
            collection.AddSingleton <IPaymentTransactionQuery, InMemoryPaymentTransactionQuery>();

            collection.AddTransient(IoC =>
            {
                ObjectCache objectCache = Substitute.For <ObjectCache>();

                objectCache
                .Get(ValidTransactionId, Arg.Any <string>())
                .Returns(new PaymentTransaction(new Card("4916690086480301", 12, 2022), 19.99m, DateTime.Now, true));

                objectCache
                .Get(InvalidTransactionId, Arg.Any <string>())
                .Returns(null);

                return(objectCache);
            });
            collection.AddTransient <IPaymentValidator, PaymentValidator>();
            collection.AddTransient <IPaymentService, PaymentService>();
            collection.AddTransient <IBank>(_ =>
            {
                IBank bank = Substitute.For <IBank>();
                bank.CreatePayment(Arg.Any <Payment>()).Returns(Task.FromResult(new ProcessedPayment()
                {
                    success = true
                }));
                return(bank);
            });
        }
Пример #2
0
        public async Task <PaymentResponse> MakePayment(Payment payment, Card card)
        {
            try
            {
                var bankPayment = await bank.CreatePayment(payment);

                return(new SuccessfulPaymentResponse(Guid.NewGuid(), card));
            }
            catch (Refit.ApiException bankRejects)
            {
                return(new FailedPaymentResponse(Guid.Empty));
            }
            catch
            {
                throw;
            }
        }