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); }
public PaymentService( IAccountDataStore mainAccountDataStore, IAccountDataStore backupAccountDataStore, IDataStoreTypeProvider dataStoreTypeProvider) { _backupAccountDataStore = backupAccountDataStore; _dataStoreTypeProvider = dataStoreTypeProvider; _accountDataStore = mainAccountDataStore; }
// // 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()); }
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); }
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 }); }
public BalanceService(IAccountDataStore accountDataStore) { _accountDataStore = accountDataStore; }
public AccountUpdateHttpTrigger( IAccountDataStore accountDataStore) { _accountDataStore = accountDataStore; }
public AccountAddHttpTrigger( IAccountDataStore accountDataStore) { _accountDataStore = accountDataStore; }
public AccountService( IDataStoreFactory dataStoreFactory, IAppConfiguration appConfiguration) { _dataStore = dataStoreFactory.CreateDataStore(appConfiguration.DataStoreType); }
public void SetUp() { _fixture = new Fixture(); _sut = new AccountDataStore(); }
public PaymentService() { _backupAccountDataStore = new BackupAccountDataStore(); _accountDataStore = new AccountDataStore(); _dataStoreTypeProvider = new DataStoreTypeProvider(); }
public AccountService(IAccountDataStoreFactory accountDataStoreFactory) { _accountDataStore = accountDataStoreFactory.GetInstance(); }
public HomeController(IAccountDataStore accountDataStore, ITransactionDataStore transactionDataStore) { _accountDataStore = accountDataStore; _transactionDataStore = transactionDataStore; }
public RegisterController(IAccountDataStore accountDataStore) { _accountDataStore = accountDataStore; }
public PaymentService(IAccountDataStore accountDataStore, IPaymentSchemeValidatorService paymentSchemeValidatorService) { _accountDataStore = accountDataStore; _paymentSchemeValidatorService = paymentSchemeValidatorService; }
public PaymentService(IAccountDataStore accountDataStore, IValidationService validationService) { _accountDataStore = accountDataStore; _validationService = validationService; }
public PaymentService(IAccountDataStore accountDataStore, IValidatePaymentFactory validatePaymentFactory) { _accountDataStore = accountDataStore; _validatePaymentFactory = validatePaymentFactory; }
public AccountFetchHttpTrigger( IAccountDataStore accountDataStore) { _accountDataStore = accountDataStore; }
public PaymentService(IAccountDataStore accountDataStore, IPaymentSchemeValidationHandler paymentSchemeValidationHandler) { _accountDataStore = accountDataStore; _paymentSchemeValidationHandler = paymentSchemeValidationHandler; }
public LoginController(IAccountDataStore accountDataStore) { _accountDataStore = accountDataStore; }
public PaymentService(IAccountDataStore accountDataStore) { AccountDataStore = accountDataStore; }
public PaymentService(IAccountDataStoreFactory accountDataStoreFactory, IPaymentAccountStateValidator accountStateValidator) { _accountStateValidator = accountStateValidator; _accountDataStore = accountDataStoreFactory.Create(); }
// // NOTE Normally would Inject In DataStore - Configured at Startup with relevant Store Type // public PaymentService(IAccountDataStore dataStore) { _accountDataStore = dataStore; }
public PaymentService(IAccountDataStore accountDataStore, IPaymentTypeRule paymentTypeRule) { AccountDataStore = accountDataStore; _paymentTypeRule = paymentTypeRule; }