Esempio n. 1
0
        public MakePaymentResult MakePayment(MakePaymentRequest request)
        {
            var result = new MakePaymentResult {
                Success = false
            };

            if (request == null)
            {
                return(result);
            }

            IAccountDataStore accountDataStore = _accountDataStoreFactory.BuildAccountDataStore();

            IValidator validator = _validatorFactory.BuildValidator(request);

            Account account = accountDataStore.GetAccount(request.DebtorAccountNumber);

            if (account == null || !validator.AccountCanMakePayment(account))
            {
                return(result);
            }

            account.Balance -= request.Amount;

            accountDataStore.UpdateAccount(account);

            result.Success = true;

            return(result);
        }
Esempio n. 2
0
 public PaymentService(
     IAccountDataStore mainAccountDataStore,
     IAccountDataStore backupAccountDataStore,
     IDataStoreTypeProvider dataStoreTypeProvider)
 {
     _backupAccountDataStore = backupAccountDataStore;
     _dataStoreTypeProvider  = dataStoreTypeProvider;
     _accountDataStore       = mainAccountDataStore;
 }
Esempio n. 3
0
        //
        // Default Constructor - Sets DataStore by reading Config
        //
        public PaymentService()
        {
            var dataStoreType = ConfigurationManager.AppSettings["DataStoreType"];

            if (dataStoreType == "Backup")
            {
                _accountDataStore = new BackupAccountDataStore();
            }
            else
            {
                _accountDataStore = new AccountDataStore();
            }
        }
        public void DefaultsToLiveDataStore(string settingValue)
        {
            // Arrange
            var configuration = new Mock <IConfigurationProvider>();

            configuration.Setup(c => c.TryGetDataStoreType(out settingValue)).Returns(true);
            var factory = new AccountDataStoreFactory(configuration.Object);

            // Act
            IAccountDataStore datastore = factory.BuildAccountDataStore();

            // Assert
            Assert.AreEqual(typeof(AccountDataStore), datastore.GetType());
        }
        public void UsesBackupDataStoreWhenConfigured()
        {
            // Arrange
            string settingValue  = "Backup";
            var    configuration = new Mock <IConfigurationProvider>();

            configuration.Setup(c => c.TryGetDataStoreType(out settingValue)).Returns(true);
            var factory = new AccountDataStoreFactory(configuration.Object);

            // Act
            IAccountDataStore datastore = factory.BuildAccountDataStore();

            // Assert
            Assert.AreEqual(typeof(BackupAccountDataStore), datastore.GetType());
        }
Esempio n. 6
0
        public PaymentService(IValidator validator,
                              IAccountDataStore accountDataStore,
                              IBalanceService balanceService)
        {
            _validator        = validator;
            _accountDataStore = accountDataStore;
            _balanceService   = balanceService;

            _paymentSchemes = new List <IPaymentProcessor>
            {
                new BacsPaymentProcessor(),
                new ChapsPaymentProcessor(),
                new FasterPaymentProcessor()
            };
        }
        public virtual IAccountDataStore GetAccountDataStore()
        {
            IAccountDataStore accountDataStore = null;

            var dataStoreType = _appConfig.GetValueByKey("DataStoreType");

            switch (dataStoreType)
            {
            case "Backup":
            {
                accountDataStore = new BackupAccountDataStore();
                break;
            }

            default:
            {
                accountDataStore = new AccountDataStore();
                break;
            }
            }

            return(accountDataStore);
        }
Esempio n. 8
0
        public MakePaymentResult MakePayment(MakePaymentRequest request)
        {
            try
            {
                IAccountDataStore dataStore = accountRepository.GetDataStore();

                Account debtorAccount   = dataStore.GetAccount(request.DebtorAccountNumber);
                Account creditorAccount = dataStore.GetAccount(request.CreditorAccountNumber);

                if (debtorAccount == null)
                {
                    throw new ArgumentException("Debtor account not found.");
                }
                else if (creditorAccount == null)
                {
                    throw new ArgumentException("Creditor account not found.");
                }

                debtorAccount.Debit(request.Amount, request.PaymentScheme);
                creditorAccount.Credit(request.Amount, request.PaymentScheme);

                //Normally these two operations would be part of a transaction, e.g. the repository would implement the UnitOfWork pattern
                dataStore.UpdateAccount(debtorAccount);
                dataStore.UpdateAccount(creditorAccount);
            } catch (Exception ex)
            {
                //Normall we would the log error here with an abstraction of a logging component (ILogger etc) injected in this service

                return(new MakePaymentResult {
                    Success = false
                });
            }

            return(new MakePaymentResult {
                Success = true
            });
        }
Esempio n. 9
0
 public BalanceService(IAccountDataStore accountDataStore)
 {
     _accountDataStore = accountDataStore;
 }
Esempio n. 10
0
 public AccountUpdateHttpTrigger(
     IAccountDataStore accountDataStore)
 {
     _accountDataStore = accountDataStore;
 }
Esempio n. 11
0
 public AccountAddHttpTrigger(
     IAccountDataStore accountDataStore)
 {
     _accountDataStore = accountDataStore;
 }
Esempio n. 12
0
 public AccountService(
     IDataStoreFactory dataStoreFactory,
     IAppConfiguration appConfiguration)
 {
     _dataStore = dataStoreFactory.CreateDataStore(appConfiguration.DataStoreType);
 }
 public void SetUp()
 {
     _fixture = new Fixture();
     _sut     = new AccountDataStore();
 }
Esempio n. 14
0
 public PaymentService()
 {
     _backupAccountDataStore = new BackupAccountDataStore();
     _accountDataStore       = new AccountDataStore();
     _dataStoreTypeProvider  = new DataStoreTypeProvider();
 }
Esempio n. 15
0
 public AccountService(IAccountDataStoreFactory accountDataStoreFactory)
 {
     _accountDataStore = accountDataStoreFactory.GetInstance();
 }
Esempio n. 16
0
 public HomeController(IAccountDataStore accountDataStore, ITransactionDataStore transactionDataStore)
 {
     _accountDataStore     = accountDataStore;
     _transactionDataStore = transactionDataStore;
 }
Esempio n. 17
0
 public RegisterController(IAccountDataStore accountDataStore)
 {
     _accountDataStore = accountDataStore;
 }
Esempio n. 18
0
 public PaymentService(IAccountDataStore accountDataStore, IPaymentSchemeValidatorService paymentSchemeValidatorService)
 {
     _accountDataStore = accountDataStore;
     _paymentSchemeValidatorService = paymentSchemeValidatorService;
 }
Esempio n. 19
0
 public PaymentService(IAccountDataStore accountDataStore, IValidationService validationService)
 {
     _accountDataStore  = accountDataStore;
     _validationService = validationService;
 }
Esempio n. 20
0
 public PaymentService(IAccountDataStore accountDataStore, IValidatePaymentFactory validatePaymentFactory)
 {
     _accountDataStore       = accountDataStore;
     _validatePaymentFactory = validatePaymentFactory;
 }
Esempio n. 21
0
 public AccountFetchHttpTrigger(
     IAccountDataStore accountDataStore)
 {
     _accountDataStore = accountDataStore;
 }
Esempio n. 22
0
 public PaymentService(IAccountDataStore accountDataStore, IPaymentSchemeValidationHandler paymentSchemeValidationHandler)
 {
     _accountDataStore = accountDataStore;
     _paymentSchemeValidationHandler = paymentSchemeValidationHandler;
 }
Esempio n. 23
0
 public LoginController(IAccountDataStore accountDataStore)
 {
     _accountDataStore = accountDataStore;
 }
 public PaymentService(IAccountDataStore accountDataStore)
 {
     AccountDataStore = accountDataStore;
 }
 public PaymentService(IAccountDataStoreFactory accountDataStoreFactory,
                       IPaymentAccountStateValidator accountStateValidator)
 {
     _accountStateValidator = accountStateValidator;
     _accountDataStore      = accountDataStoreFactory.Create();
 }
Esempio n. 26
0
 //
 // NOTE Normally would Inject In DataStore - Configured at Startup with relevant Store Type
 //
 public PaymentService(IAccountDataStore dataStore)
 {
     _accountDataStore = dataStore;
 }
Esempio n. 27
0
 public PaymentService(IAccountDataStore accountDataStore, IPaymentTypeRule paymentTypeRule)
 {
     AccountDataStore = accountDataStore;
     _paymentTypeRule = paymentTypeRule;
 }