/// <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;
 }
예제 #2
0
        public void AssignDepositLimitsTest_ChecksThatDepositLimitsAreAssignedProperlyWhenLevel1IsNotVerifiedAndBalanceIsAlreadyPresent_VerifiesThroughReturnedValues()
        {
            IDepositApplicationService    depositApplicationService = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IDepositLimitRepository       depositLimitRepository    = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            StubTierLevelRetrievalService tierLevelRetrieval        = (StubTierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"];

            tierLevelRetrieval.SetTierLevel("Tier 0");
            DepositLimit depositLimit = depositLimitRepository.GetLimitByTierLevelAndCurrency("Tier 0", LimitsCurrency.Default.ToString());

            Assert.IsNotNull(depositLimit);
            Assert.AreEqual(0, depositLimit.DailyLimit);
            Assert.AreEqual(0, depositLimit.MonthlyLimit);
            AccountId accountId = new AccountId(123);
            Currency  currency  = new Currency("BTC", true);

            DepositLimitThresholdsRepresentation depositLimitThresholds = depositApplicationService.GetThresholdLimits(accountId.Value, currency.Name);

            Assert.IsNotNull(depositLimitThresholds);
            Assert.AreEqual(depositLimit.DailyLimit, depositLimitThresholds.DailyLimit);
            Assert.AreEqual(depositLimit.MonthlyLimit, depositLimitThresholds.MonthlyLimit);
            Assert.AreEqual(0, depositLimitThresholds.DailyLimitUsed);
            Assert.AreEqual(0, depositLimitThresholds.MonthlyLimitUsed);
            Assert.AreEqual(0, depositLimitThresholds.CurrentBalance);
            Assert.AreEqual(0, depositLimitThresholds.MaximumDeposit);
        }
예제 #3
0
        public void DepositArrivedAndConfirmedTest_ChecksThatANewDepositInstanceIsCreatedAndConfirmedAsExpected_VerifiesThroughDatabaseQuery()
        {
            IDepositApplicationService  depositApplicationService  = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];
            IBalanceRepository          balanceRepository          = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"];
            IDepositRepository          depositRepository          = (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"];
            IDepositLimitRepository     depositLimitRepository     = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];

            AccountId      accountId      = new AccountId(123);
            Currency       currency       = new Currency("BTC", true);
            BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1");
            TransactionId  transactionId  = new TransactionId("transactionid1");
            string         category       = BitcoinConstants.ReceiveCategory;

            DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress, AddressStatus.New, DateTime.Now, accountId);

            fundsPersistenceRepository.SaveOrUpdate(depositAddress);
            DepositLimit depositLimit = depositLimitRepository.GetLimitByTierLevelAndCurrency("Tier 1", "Default");

            Assert.IsNotNull(depositLimit, "DepositLimit used initially to compare later");

            List <Tuple <string, string, decimal, string> > transactionsList = new List <Tuple <string, string, decimal, string> >();

            // Provide the amount which is greater than the daily limit
            transactionsList.Add(new Tuple <string, string, decimal, string>(bitcoinAddress.Value, transactionId.Value,
                                                                             depositLimit.DailyLimit - 0.01M, category));
            depositApplicationService.OnDepositArrival(currency.Name, transactionsList);

            // Deposit Transaction first arrival
            Deposit deposit = depositRepository.GetDepositByTransactionId(transactionId);

            Assert.IsNotNull(deposit);
            Assert.AreEqual(depositLimit.DailyLimit - 0.01M, deposit.Amount);
            Assert.AreEqual(transactionId.Value, deposit.TransactionId.Value);
            Assert.AreEqual(accountId.Value, deposit.AccountId.Value);
            Assert.AreEqual(bitcoinAddress.Value, deposit.BitcoinAddress.Value);
            Assert.AreEqual(TransactionStatus.Pending, deposit.Status);
            Balance balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);

            Assert.IsNull(balance);

            // Deposit Confirmation
            depositApplicationService.OnDepositConfirmed(transactionId.Value, 7);
            deposit = depositRepository.GetDepositByTransactionId(transactionId);
            Assert.IsNotNull(deposit);
            Assert.AreEqual(depositLimit.DailyLimit - 0.01M, deposit.Amount);
            Assert.AreEqual(transactionId.Value, deposit.TransactionId.Value);
            Assert.AreEqual(accountId.Value, deposit.AccountId.Value);
            Assert.AreEqual(bitcoinAddress.Value, deposit.BitcoinAddress.Value);
            Assert.AreEqual(TransactionStatus.Confirmed, deposit.Status);

            // Balance instance now will have been created
            balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);
            Assert.IsNotNull(balance);
            Assert.AreEqual(depositLimit.DailyLimit - 0.01M, balance.AvailableBalance);
            Assert.AreEqual(depositLimit.DailyLimit - 0.01M, balance.CurrentBalance);
            Assert.AreEqual(0, balance.PendingBalance);
            Assert.IsFalse(balance.IsFrozen);
        }
예제 #4
0
        public void DepositArrivedStandaloneFailedTest_TestsIfTheOperationIsAbortedWhenAmountIshigherThanThresholdLimit_VerifiesThroughQueryingDatabaseIsntances()
        {
            // Tests the event handler DepositArrived by directly sending data
            IDepositApplicationService    depositApplicationService  = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IFundsPersistenceRepository   fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];
            IBalanceRepository            balanceRepository          = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"];
            ILedgerRepository             ledgerRepository           = (ILedgerRepository)ContextRegistry.GetContext()["LedgerRepository"];
            IDepositRepository            depositRepository          = (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"];
            IDepositLimitRepository       depositLimitRepository     = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            StubTierLevelRetrievalService tierLevelRetrievalService  = (ITierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"] as StubTierLevelRetrievalService;

            Assert.IsNotNull(tierLevelRetrievalService);
            tierLevelRetrievalService.SetTierLevel(TierConstants.TierLevel1);
            AccountId      accountId      = new AccountId(123);
            Currency       currency       = new Currency("BTC", true);
            BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1");
            TransactionId  transactionId  = new TransactionId("transactionid1");

            DepositLimit depositLimit = depositLimitRepository.GetLimitByTierLevelAndCurrency(TierConstants.TierLevel1,
                                                                                              LimitsCurrency.Default.ToString());
            decimal amount   = depositLimit.DailyLimit + 0.001M;
            string  category = BitcoinConstants.ReceiveCategory;

            DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress, AddressStatus.New, DateTime.Now,
                                                               accountId);

            fundsPersistenceRepository.SaveOrUpdate(depositAddress);

            Balance balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);

            Assert.IsNull(balance);

            IList <Ledger> ledgers = ledgerRepository.GetLedgerByAccountIdAndCurrency(currency.Name, accountId);

            Assert.AreEqual(ledgers.Count, 0);

            List <Tuple <string, string, decimal, string> > transactionsList = new List <Tuple <string, string, decimal, string> >();

            transactionsList.Add(new Tuple <string, string, decimal, string>(bitcoinAddress.Value, transactionId.Value, amount, category));
            depositApplicationService.OnDepositArrival(currency.Name, transactionsList);

            Deposit deposit = depositRepository.GetDepositByTransactionId(transactionId);

            Assert.IsNotNull(deposit);
            Assert.AreEqual(amount, deposit.Amount);
            Assert.AreEqual(currency.Name, deposit.Currency.Name);
            Assert.AreEqual(accountId.Value, deposit.AccountId.Value);
            Assert.AreEqual(bitcoinAddress.Value, deposit.BitcoinAddress.Value);
            Assert.AreEqual(transactionId.Value, deposit.TransactionId.Value);
            Assert.AreEqual(TransactionStatus.Frozen, deposit.Status);

            // Confirm that the balance for the user has been frozen for this account
            balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);
            Assert.IsNotNull(balance);
            Assert.IsTrue(balance.IsFrozen);
        }
        public void Setup()
        {
            _depositLimitRepository = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            _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();
        }
        /// <summary>
        /// Default Constructor
        /// </summary>
        private DepositApplicationService(IFundsValidationService fundsValidationService, IClientInteractionService clientInteractionService,
                                          IFundsPersistenceRepository fundsPersistenceRepository, IDepositAddressRepository depositAddressRepository,
                                          IBalanceRepository balanceRepository, IDepositRepository depositRepository, IDepositLimitRepository depositLimitRepository)
        {
            _fundsValidationService     = fundsValidationService;
            _clientInteractionService   = clientInteractionService;
            _fundsPersistenceRepository = fundsPersistenceRepository;
            _depositAddressRepository   = depositAddressRepository;
            _balanceRepository          = balanceRepository;
            _depositRepository          = depositRepository;
            _depositLimitRepository     = depositLimitRepository;

            _clientInteractionService.DepositArrived   += OnDepositArrival;
            _clientInteractionService.DepositConfirmed += OnDepositConfirmed;
        }
예제 #8
0
        public void AssignDepositLimitsTest_ChecksThatDepositLimitsAreNotAssignedWhenNoDepositLimitIsFound_VerifiesThroughReturnedValues()
        {
            IDepositApplicationService    depositApplicationService = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IDepositLimitRepository       depositLimitRepository    = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            StubTierLevelRetrievalService tierLevelRetrieval        = (StubTierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"];

            // Specify invalid tier level
            tierLevelRetrieval.SetTierLevel("Tier 6");
            DepositLimit depositLimit = depositLimitRepository.GetLimitByTierLevelAndCurrency("Tier 0", LimitsCurrency.Default.ToString());

            Assert.IsNotNull(depositLimit);
            Assert.AreEqual(0, depositLimit.DailyLimit);
            Assert.AreEqual(0, depositLimit.MonthlyLimit);
            AccountId accountId = new AccountId(123);
            Currency  currency  = new Currency("BTC", true);

            // Exception occurs here because there is no such level as Tier 6
            depositApplicationService.GetThresholdLimits(accountId.Value, currency.Name);
        }
예제 #9
0
        public void DepositArrivedFailTest_VerifiesThatNewDepositWithAMountGreaterThanLimitsIsSuspendedAndAccountBalanceFrozen_VerifiesThroughDatabaseQuery()
        {
            IDepositApplicationService  depositApplicationService  = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];
            IBalanceRepository          balanceRepository          = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"];
            IDepositRepository          depositRepository          = (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"];
            IDepositLimitRepository     depositLimitRepository     = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];

            AccountId      accountId      = new AccountId(123);
            Currency       currency       = new Currency("BTC", true);
            BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1");
            TransactionId  transactionId  = new TransactionId("transactionid1");
            string         category       = BitcoinConstants.ReceiveCategory;

            DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress, AddressStatus.New, DateTime.Now, accountId);

            fundsPersistenceRepository.SaveOrUpdate(depositAddress);
            DepositLimit depositLimit = depositLimitRepository.GetLimitByTierLevelAndCurrency("Tier 1", "Default");

            Assert.IsNotNull(depositLimit, "DepositLimit used initially to compare later");

            List <Tuple <string, string, decimal, string> > transactionsList = new List <Tuple <string, string, decimal, string> >();

            // Provide the amount which is greater than the daily limit
            transactionsList.Add(new Tuple <string, string, decimal, string>(bitcoinAddress.Value, transactionId.Value,
                                                                             depositLimit.DailyLimit + 0.001M, category));
            depositApplicationService.OnDepositArrival(currency.Name, transactionsList);

            Deposit deposit = depositRepository.GetDepositByTransactionId(transactionId);

            Assert.IsNotNull(deposit);
            Assert.AreEqual(TransactionStatus.Frozen, deposit.Status);
            Balance balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);

            Assert.IsNotNull(balance);
            Assert.IsTrue(balance.IsFrozen);
        }
예제 #10
0
        public void AssignDepositLimits2Test_ChecksThatDepositLimitsAreAssignedProperlyWhenLevel1IsVerifiedAndBalanceIsAlreadyPresent_VerifiesThroughReturnedValues()
        {
            IDepositApplicationService  depositApplicationService  = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IDepositLimitRepository     depositLimitRepository     = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];

            DepositLimit depositLimit  = depositLimitRepository.GetLimitByTierLevelAndCurrency("Tier 1", LimitsCurrency.Default.ToString());
            AccountId    accountId     = new AccountId(123);
            Currency     currency      = new Currency("BTC", true);
            decimal      balanceAmount = 100;
            Balance      balance       = new Balance(currency, accountId, balanceAmount, balanceAmount);

            fundsPersistenceRepository.SaveOrUpdate(balance);

            DepositLimitThresholdsRepresentation depositLimitThresholds = depositApplicationService.GetThresholdLimits(accountId.Value, currency.Name);

            Assert.IsNotNull(depositLimitThresholds);
            Assert.AreEqual(depositLimit.DailyLimit, depositLimitThresholds.DailyLimit);
            Assert.AreEqual(depositLimit.MonthlyLimit, depositLimitThresholds.MonthlyLimit);
            Assert.AreEqual(0, depositLimitThresholds.DailyLimitUsed);
            Assert.AreEqual(0, depositLimitThresholds.MonthlyLimitUsed);
            Assert.AreEqual(balanceAmount, depositLimitThresholds.CurrentBalance);
            Assert.AreEqual(depositLimit.DailyLimit, depositLimitThresholds.MaximumDeposit);
        }
예제 #11
0
        public void DepositArrivedAndConfirmedEventTest_TestsThatDepositArrivedEventIsHandledAsExpected_VerifiesThroughRaisedEvent()
        {
            // Withdraw is submitted and events are actually raised from the CoinClientService
            // Over the limit deposit so account and deposit are frozen
            IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];
            IBalanceRepository          balanceRepository          = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"];
            IDepositRepository          depositRepository          = (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"];
            IWithdrawRepository         withdrawRepository         = (IWithdrawRepository)ContextRegistry.GetContext()["WithdrawRepository"];
            IDepositLimitRepository     depositLimitRepository     = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            IWithdrawApplicationService withdrawApplicationService = (IWithdrawApplicationService)ContextRegistry.GetContext()["WithdrawApplicationService"];

            AccountId      accountId      = new AccountId(123);
            Currency       currency       = new Currency("BTC", true);
            BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1");
            TransactionId  transactionId  = new TransactionId("transactionid1");

            DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress, AddressStatus.New, DateTime.Now,
                                                               accountId);

            fundsPersistenceRepository.SaveOrUpdate(depositAddress);
            DepositLimit depositLimit = depositLimitRepository.GetLimitByTierLevelAndCurrency("Tier 1", "Default");

            Assert.IsNotNull(depositLimit, "DepositLimit used initially to compare later");
            decimal amount = depositLimit.DailyLimit - 0.001M;

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            Balance balance = new Balance(currency, accountId, 10, 10);

            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);
            // Get the interval after which the withdraw will be submitted. Once submitted to the StubClientService, the events
            // of DepositArrived will be raised and handled in Deposit APplicationService, which will create a new Deposit
            // instance and save in database
            int withdrawInterval = Convert.ToInt16(ConfigurationManager.AppSettings.Get("WithdrawSubmitInterval"));

            manualResetEvent.WaitOne(withdrawInterval + 2000);

            Withdraw withdraw = withdrawRepository.GetWithdrawByWithdrawId(commitWithdrawResponse.WithdrawId);

            Assert.IsNotNull(withdraw);
            Deposit deposit = depositRepository.GetDepositByTransactionId(transactionId);

            Assert.IsNotNull(deposit);
            Assert.AreEqual(amount - withdraw.Fee, deposit.Amount);
            Assert.AreEqual(withdraw.TransactionId.Value, deposit.TransactionId.Value);
            Assert.AreEqual(accountId.Value, deposit.AccountId.Value);
            Assert.AreEqual(bitcoinAddress.Value, deposit.BitcoinAddress.Value);
            Assert.AreEqual(TransactionStatus.Confirmed, deposit.Status);
            balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);
            Assert.IsNotNull(balance);

            // Balance instance now will have been created
            balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);
            Assert.IsNotNull(balance);
            Assert.AreEqual(0, balance.PendingBalance);
            Assert.IsFalse(balance.IsFrozen);
        }
예제 #12
0
        public void DepositArrivedStandaloneTest_TestsIfTheOperationProceedsAsExpectedWHenANewDepositArrives_VerifiesThroughQueryingDatabaseIsntances()
        {
            // Tests the event handler DepositArrived by directly sending data
            IDepositApplicationService    depositApplicationService  = (IDepositApplicationService)ContextRegistry.GetContext()["DepositApplicationService"];
            IFundsPersistenceRepository   fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];
            IBalanceRepository            balanceRepository          = (IBalanceRepository)ContextRegistry.GetContext()["BalanceRepository"];
            ILedgerRepository             ledgerRepository           = (ILedgerRepository)ContextRegistry.GetContext()["LedgerRepository"];
            IDepositRepository            depositRepository          = (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"];
            IDepositAddressRepository     depositAddressRepository   = (IDepositAddressRepository)ContextRegistry.GetContext()["DepositAddressRepository"];
            IDepositLimitRepository       depositLimitRepository     = (IDepositLimitRepository)ContextRegistry.GetContext()["DepositLimitRepository"];
            StubTierLevelRetrievalService tierLevelRetrieval         = (StubTierLevelRetrievalService)ContextRegistry.GetContext()["TierLevelRetrievalService"];

            tierLevelRetrieval.SetTierLevel(TierConstants.TierLevel1);
            AccountId      accountId      = new AccountId(123);
            Currency       currency       = new Currency("BTC", true);
            BitcoinAddress bitcoinAddress = new BitcoinAddress("bitcoinaddress1");
            TransactionId  transactionId  = new TransactionId("transactionid1");
            DepositLimit   depositLimit   = depositLimitRepository.GetLimitByTierLevelAndCurrency(TierConstants.TierLevel1,
                                                                                                  LimitsCurrency.Default.ToString());
            decimal amount   = depositLimit.DailyLimit - 0.001M;
            string  category = BitcoinConstants.ReceiveCategory;

            DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress, AddressStatus.New, DateTime.Now,
                                                               accountId);

            fundsPersistenceRepository.SaveOrUpdate(depositAddress);

            Balance balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);

            Assert.IsNull(balance);

            IList <Ledger> ledgers = ledgerRepository.GetLedgerByAccountIdAndCurrency(currency.Name, accountId);

            Assert.AreEqual(ledgers.Count, 0);

            List <Tuple <string, string, decimal, string> > transactionsList = new List <Tuple <string, string, decimal, string> >();

            transactionsList.Add(new Tuple <string, string, decimal, string>(bitcoinAddress.Value, transactionId.Value, amount, category));
            depositApplicationService.OnDepositArrival(currency.Name, transactionsList);

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            manualResetEvent.WaitOne(2000);
            Deposit deposit = depositRepository.GetDepositByTransactionId(transactionId);

            Assert.IsNotNull(deposit);
            Assert.AreEqual(deposit.Amount, amount);
            Assert.AreEqual(deposit.Currency.Name, currency.Name);
            Assert.IsTrue(deposit.Currency.IsCryptoCurrency);
            Assert.AreEqual(deposit.TransactionId.Value, transactionId.Value);
            Assert.AreEqual(deposit.BitcoinAddress.Value, bitcoinAddress.Value);
            Assert.AreEqual(deposit.Status, TransactionStatus.Pending);

            depositAddress = depositAddressRepository.GetDepositAddressByAddress(bitcoinAddress);
            Assert.IsNotNull(depositAddress);
            Assert.AreEqual(depositAddress.Status, AddressStatus.Used);

            balance = balanceRepository.GetBalanceByCurrencyAndAccountId(currency, accountId);
            Assert.IsNull(balance);

            ledgers = ledgerRepository.GetLedgerByAccountIdAndCurrency(currency.Name, accountId);
            Assert.AreEqual(ledgers.Count, 0);
        }