/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public FundsValidationService(ITransactionService transactionService, IFundsPersistenceRepository fundsPersistenceRepository, IBalanceRepository balanceRepository, IFeeCalculationService feeCalculationService, IWithdrawFeesRepository withdrawFeesRepository, IWithdrawIdGeneratorService withdrawIdGeneratorService, ILedgerRepository ledgerRepository, IDepositLimitEvaluationService depositLimitEvaluationService, IDepositLimitRepository depositLimitRepository, IWithdrawLimitEvaluationService withdrawLimitEvaluationService, IWithdrawLimitRepository withdrawLimitRepository, ITierLevelRetrievalService tierLevelRetrievalService, IWithdrawRepository withdrawRepository, ITierValidationService tierValidationService, ILimitsConfigurationService limitsConfigurationService) { _transactionService = transactionService; _fundsPersistenceRepository = fundsPersistenceRepository; _balanceRepository = balanceRepository; _feeCalculationService = feeCalculationService; _withdrawFeesRepository = withdrawFeesRepository; _withdrawIdGeneratorService = withdrawIdGeneratorService; _ledgerRepository = ledgerRepository; _depositLimitEvaluationService = depositLimitEvaluationService; _depositLimitRepository = depositLimitRepository; _withdrawLimitEvaluationService = withdrawLimitEvaluationService; _withdrawLimitRepository = withdrawLimitRepository; _tierLevelRetrievalService = tierLevelRetrievalService; _withdrawRepository = withdrawRepository; _tierValidationService = tierValidationService; _limitsConfigurationService = limitsConfigurationService; }
public void AssignWithdrawLimitsTest_TestsIfWithdrawLimitsGetAsignedProperlyWhenTier1IsNotVerified_VerifiesThroughReturnedValue() { IWithdrawApplicationService withdrawApplicationService = (IWithdrawApplicationService)ContextRegistry.GetContext()["WithdrawApplicationService"]; IWithdrawLimitRepository withdrawLimitRepository = (IWithdrawLimitRepository)ContextRegistry.GetContext()["WithdrawLimitRepository"]; IWithdrawFeesRepository withdrawFeesRepository = (IWithdrawFeesRepository)ContextRegistry.GetContext()["WithdrawFeesRepository"]; StubTierLevelRetrievalService tierLevelRetrievalService = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService; Assert.IsNotNull(tierLevelRetrievalService); tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel0); AccountId accountId = new AccountId(123); Currency currency = new Currency("BTC", true); WithdrawLimit withdrawLimit = withdrawLimitRepository.GetLimitByTierLevelAndCurrency("Tier 1", LimitsCurrency.Default.ToString()); Assert.IsNotNull(withdrawLimit); WithdrawFees withdrawFees = withdrawFeesRepository.GetWithdrawFeesByCurrencyName(currency.Name); Assert.IsNotNull(withdrawFees); WithdrawLimitRepresentation withdrawLimitRepresentation = withdrawApplicationService.GetWithdrawLimitThresholds(accountId.Value, currency.Name); Assert.IsNotNull(withdrawLimitRepresentation); Assert.AreEqual(currency.Name, withdrawLimitRepresentation.Currency); Assert.AreEqual(accountId.Value, withdrawLimitRepresentation.AccountId); Assert.AreEqual(0, withdrawLimitRepresentation.DailyLimit); Assert.AreEqual(0, withdrawLimitRepresentation.MonthlyLimit); Assert.AreEqual(0, withdrawLimitRepresentation.DailyLimitUsed); Assert.AreEqual(0, withdrawLimitRepresentation.MonthlyLimitUsed); Assert.AreEqual(0, withdrawLimitRepresentation.CurrentBalance); Assert.AreEqual(withdrawFees.Fee, withdrawLimitRepresentation.Fee); Assert.AreEqual(withdrawFees.MinimumAmount, withdrawLimitRepresentation.MinimumAmount); Assert.AreEqual(0, withdrawLimitRepresentation.Withheld); Assert.AreEqual(0, withdrawLimitRepresentation.MaximumWithdraw); }
public void WithdrawFailedTest_TestsIfWithdrawFailsBecauseOfNotEnoughBalance_VerifiesThroughDatabaseQueries() { IWithdrawApplicationService withdrawApplicationService = (IWithdrawApplicationService)ContextRegistry.GetContext()["WithdrawApplicationService"]; StubTierLevelRetrievalService tierLevelRetrievalService = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService; IWithdrawLimitRepository withdrawLimitRepository = (IWithdrawLimitRepository)ContextRegistry.GetContext()["WithdrawLimitRepository"]; IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"]; Assert.IsNotNull(tierLevelRetrievalService); tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel1); AccountId accountId = new AccountId(123); Currency currency = new Currency("BTC", true); BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1"); WithdrawLimit withdrawLimit = withdrawLimitRepository.GetLimitByTierLevelAndCurrency(TierConstants.TierLevel1, LimitsCurrency.Default.ToString()); Assert.IsNotNull(withdrawLimit); decimal amount = withdrawLimit.DailyLimit + 0.001M; Balance balance = new Balance(currency, accountId, amount - 1, amount - 1); fundsPersistenceRepository.SaveOrUpdate(balance); withdrawApplicationService.CommitWithdrawal(new CommitWithdrawCommand(accountId.Value, currency.Name, currency.IsCryptoCurrency, bitcoinAddress.Value, amount)); }
public void Setup() { _withdrawLimitRepository = (IWithdrawLimitRepository)ContextRegistry.GetContext()["WithdrawLimitRepository"]; _persistanceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"]; var connection = ConfigurationManager.ConnectionStrings["MySql"].ToString(); _databaseUtility = new DatabaseUtility(connection); _databaseUtility.Create(); _databaseUtility.Populate(); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public LimitsConfigurationService(IDepositLimitRepository depositLimitRepository, IDepositLimitEvaluationService depositLimitEvaluationService, IWithdrawLimitRepository withdrawLimitRepository, IWithdrawLimitEvaluationService withdrawLimitEvaluationService, IBboCrossContextService bboCrossContextService) { _depositLimitRepository = depositLimitRepository; _depositLimitEvaluationService = depositLimitEvaluationService; _withdrawLimitRepository = withdrawLimitRepository; _withdrawLimitEvaluationService = withdrawLimitEvaluationService; _bboCrossContextService = bboCrossContextService; ConfigureCurrencyType(); }
public void WithdrawSuccessfulTest_TestsIfWithdrawIsSuccessfulWhenTierLevelIsHighEnough_VerifiesThroughDatabaseQueries() { IWithdrawApplicationService withdrawApplicationService = (IWithdrawApplicationService)ContextRegistry.GetContext()["WithdrawApplicationService"]; IWithdrawRepository withdrawRepository = (IWithdrawRepository)ContextRegistry.GetContext()["WithdrawRepository"]; IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"]; IBalanceRepository balanceRepository = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"]; IWithdrawFeesRepository withdrawFeesRepository = (IWithdrawFeesRepository)ContextRegistry.GetContext()["WithdrawFeesRepository"]; StubTierLevelRetrievalService tierLevelRetrievalService = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService; IWithdrawLimitRepository withdrawLimitRepository = (IWithdrawLimitRepository)ContextRegistry.GetContext()["WithdrawLimitRepository"]; Assert.IsNotNull(tierLevelRetrievalService); tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel1); AccountId accountId = new AccountId(123); Currency currency = new Currency("BTC", true); BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1"); WithdrawLimit withdrawLimit = withdrawLimitRepository.GetLimitByTierLevelAndCurrency(TierConstants.TierLevel1, LimitsCurrency.Default.ToString()); Assert.IsNotNull(withdrawLimit); decimal amount = withdrawLimit.DailyLimit; Balance balance = new Balance(currency, accountId, amount + 1, amount + 1); fundsPersistenceRepository.SaveOrUpdate(balance); CommitWithdrawResponse commitWithdrawResponse = withdrawApplicationService.CommitWithdrawal(new CommitWithdrawCommand(accountId.Value, currency.Name, currency.IsCryptoCurrency, bitcoinAddress.Value, amount)); Assert.IsNotNull(commitWithdrawResponse); Assert.IsTrue(commitWithdrawResponse.CommitSuccessful); Withdraw withdraw = withdrawRepository.GetWithdrawByWithdrawId(commitWithdrawResponse.WithdrawId); Assert.IsNotNull(withdraw); Assert.AreEqual(accountId.Value, withdraw.AccountId.Value); Assert.AreEqual(currency.Name, withdraw.Currency.Name); Assert.AreEqual(currency.IsCryptoCurrency, withdraw.Currency.IsCryptoCurrency); Assert.AreEqual(amount - withdraw.Fee, withdraw.Amount); Assert.AreEqual(TransactionStatus.Pending, withdraw.Status); WithdrawFees withdrawFees = withdrawFeesRepository.GetWithdrawFeesByCurrencyName(currency.Name); Assert.IsNotNull(withdrawFees); balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId); Assert.IsNotNull(balance); Assert.AreEqual((amount + 1) - (amount), balance.AvailableBalance); Assert.AreEqual(amount + 1, balance.CurrentBalance); Assert.AreEqual(amount, balance.PendingBalance); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public WithdrawApplicationService(IFundsPersistenceRepository fundsPersistenceRepository, IWithdrawAddressRepository withdrawAddressRepository, IFundsValidationService fundsValidationService, IWithdrawRepository withdrawRepository, IClientInteractionService clientInteractionService, IDepositAddressRepository depositAddressRepository, IWithdrawLimitRepository withdrawLimitRepository, IBalanceRepository balanceRepository) { _fundsPersistenceRepository = fundsPersistenceRepository; _withdrawAddressRepository = withdrawAddressRepository; _fundsValidationService = fundsValidationService; _withdrawRepository = withdrawRepository; _withdrawSubmissionService = clientInteractionService; _depositAddressRepository = depositAddressRepository; _withdrawLimitRepository = withdrawLimitRepository; _balanceRepository = balanceRepository; _withdrawSubmissionService.WithdrawExecuted += this.WithdrawExecuted; }
public void WithdrawExecutedEventTest_ChecksThatTheEventIsProperlyRaisedAndHandledWhenWithdrawIsSubmittedToTheNetwork_VerifiesThroughRaisedEvent() { // Withdraw is submitted and upon submission to network an event is raised confirming withdrawal execution which // is handled and balance is updated. This whole process of events firing and balance validation is checked by this // test case IWithdrawApplicationService withdrawApplicationService = (IWithdrawApplicationService)ContextRegistry.GetContext()["WithdrawApplicationService"]; IWithdrawRepository withdrawRepository = (IWithdrawRepository)ContextRegistry.GetContext()["WithdrawRepository"]; IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"]; IBalanceRepository balanceRepository = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"]; IWithdrawFeesRepository withdrawFeesRepository = (IWithdrawFeesRepository)ContextRegistry.GetContext()["WithdrawFeesRepository"]; IWithdrawLimitRepository withdrawLimitRepository = (IWithdrawLimitRepository)ContextRegistry.GetContext()["WithdrawLimitRepository"]; IClientInteractionService clientInteractionService = (IClientInteractionService)ContextRegistry.GetContext()["ClientInteractionService"]; StubTierLevelRetrievalService tierLevelRetrievalService = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService; Assert.IsNotNull(tierLevelRetrievalService); tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel1); AccountId accountId = new AccountId(123); Currency currency = new Currency(CurrencyConstants.Btc, true); BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1"); WithdrawLimit withdrawLimit = withdrawLimitRepository.GetLimitByTierLevelAndCurrency(TierConstants.TierLevel1, LimitsCurrency.Default.ToString()); Assert.IsNotNull(withdrawLimit); decimal amount = withdrawLimit.DailyLimit; Balance balance = new Balance(currency, accountId, amount + 1, amount + 1); fundsPersistenceRepository.SaveOrUpdate(balance); bool withdrawEventRaised = false; ManualResetEvent manualResetEvent = new ManualResetEvent(false); Withdraw receivedWithdraw = null; clientInteractionService.WithdrawExecuted += delegate(Withdraw incomingWithdraw) { withdrawEventRaised = true; receivedWithdraw = incomingWithdraw; manualResetEvent.Set(); }; CommitWithdrawResponse commitWithdrawResponse = withdrawApplicationService.CommitWithdrawal(new CommitWithdrawCommand(accountId.Value, currency.Name, currency.IsCryptoCurrency, bitcoinAddress.Value, amount)); Assert.IsNotNull(commitWithdrawResponse); Assert.IsTrue(commitWithdrawResponse.CommitSuccessful); manualResetEvent.WaitOne(); // Apply assertions after event has been handled Assert.IsTrue(withdrawEventRaised); Assert.IsNotNull(receivedWithdraw); Withdraw withdraw = withdrawRepository.GetWithdrawByWithdrawId(commitWithdrawResponse.WithdrawId); Assert.IsNotNull(withdraw); Assert.AreEqual(accountId.Value, withdraw.AccountId.Value); Assert.AreEqual(currency.Name, withdraw.Currency.Name); Assert.AreEqual(currency.IsCryptoCurrency, withdraw.Currency.IsCryptoCurrency); Assert.AreEqual(amount - withdraw.Fee, withdraw.Amount); Assert.AreEqual(TransactionStatus.Confirmed, withdraw.Status); Assert.AreEqual(receivedWithdraw.AccountId.Value, withdraw.AccountId.Value); Assert.AreEqual(receivedWithdraw.TransactionId.Value, withdraw.TransactionId.Value); Assert.AreEqual(receivedWithdraw.BitcoinAddress.Value, withdraw.BitcoinAddress.Value); Assert.AreEqual(receivedWithdraw.Currency.Name, withdraw.Currency.Name); Assert.AreEqual(TransactionStatus.Confirmed, withdraw.Status); Assert.AreEqual(receivedWithdraw.Amount, withdraw.Amount); Assert.AreEqual(receivedWithdraw.WithdrawId, withdraw.WithdrawId); WithdrawFees withdrawFees = withdrawFeesRepository.GetWithdrawFeesByCurrencyName(currency.Name); Assert.IsNotNull(withdrawFees); balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId); Assert.IsNotNull(balance); Assert.AreEqual((amount + 1) - (amount), balance.AvailableBalance); Assert.AreEqual((amount + 1) - (amount), balance.CurrentBalance); Assert.AreEqual(0, balance.PendingBalance); }