public void SaveDepositsAndRetreiveByBitcoinAddressTest_SavesMultipleObjectsToDatabase_ChecksIfTheyAreAsExpected() { Deposit deposit = new Deposit(new Currency("LTC", true), "1234", DateTime.Now, DepositType.Default, 2000, 0.005m, TransactionStatus.Pending, new AccountId(1), new TransactionId("transact123"), new BitcoinAddress("address123")); _persistanceRepository.SaveOrUpdate(deposit); Thread.Sleep(1000); Deposit deposit2 = new Deposit(new Currency("BTC", true), "123", DateTime.Now, DepositType.Default, 1000, 0.010m, TransactionStatus.Pending, new AccountId(1), new TransactionId("transact123"), new BitcoinAddress("address123")); _persistanceRepository.SaveOrUpdate(deposit2); List <Deposit> retrievedDepositList = _depositRepository.GetDepositsByBitcoinAddress(new BitcoinAddress("address123")); Assert.IsNotNull(retrievedDepositList); Assert.AreEqual(deposit.Currency.Name, retrievedDepositList[1].Currency.Name); Assert.AreEqual(deposit.DepositId, retrievedDepositList[1].DepositId); Assert.AreEqual(deposit.Type, retrievedDepositList[1].Type); Assert.AreEqual(deposit.Amount, retrievedDepositList[1].Amount); Assert.AreEqual(deposit.Fee, retrievedDepositList[1].Fee); Assert.AreEqual(deposit.Status, retrievedDepositList[1].Status); Assert.AreEqual(deposit.AccountId.Value, retrievedDepositList[1].AccountId.Value); Assert.AreEqual(deposit2.Currency.Name, retrievedDepositList[0].Currency.Name); Assert.AreEqual(deposit2.DepositId, retrievedDepositList[0].DepositId); Assert.AreEqual(deposit2.Type, retrievedDepositList[0].Type); Assert.AreEqual(deposit2.Amount, retrievedDepositList[0].Amount); Assert.AreEqual(deposit2.Fee, retrievedDepositList[0].Fee); Assert.AreEqual(deposit2.Status, retrievedDepositList[0].Status); Assert.AreEqual(deposit2.AccountId.Value, retrievedDepositList[0].AccountId.Value); }
public void DepositCheckNewTransactionsTest_TestIfDepositHandlingIsDoneAsExpected_VerifiesThroughReturnedValue() { // Submits withdraw to own address, after the first NewTransactionInterval has been elapsed. // Checks if new deposit has been created by the DepositAPplicationService and DepositAddress marked used if (_shouldRunTests) { ICoinClientService coinClientService = (ICoinClientService)ContextRegistry.GetContext()["BitcoinClientService"]; IFundsPersistenceRepository fundsPersistenceRepository = (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"]; IDepositAddressRepository depositAddressRepository = (IDepositAddressRepository)ContextRegistry.GetContext()["DepositAddressRepository"]; IDepositRepository depositRepository = (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"]; Currency currency = new Currency("BTC", true); AccountId accountId = new AccountId(1); string newAddress = coinClientService.CreateNewAddress(); BitcoinAddress bitcoinAddress = new BitcoinAddress(newAddress); DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress, AddressStatus.New, DateTime.Now, accountId); fundsPersistenceRepository.SaveOrUpdate(depositAddress); // Check that there is no deposit with htis address present List <Deposit> deposits = depositRepository.GetDepositsByBitcoinAddress(bitcoinAddress); Assert.AreEqual(0, deposits.Count); ManualResetEvent manualResetEvent = new ManualResetEvent(false); // Wait for the first interval to elapse, and then withdraw, because only then we will be able to figure if a // new transaction has been received manualResetEvent.WaitOne(Convert.ToInt32(coinClientService.PollingInterval + 3000)); manualResetEvent.Reset(); bool eventFired = false; coinClientService.DepositArrived += delegate(string curr, List <Tuple <string, string, decimal, string> > pendingList) { eventFired = true; manualResetEvent.Set(); }; Withdraw withdraw = new Withdraw(currency, Guid.NewGuid().ToString(), DateTime.Now, WithdrawType.Bitcoin, Amount, 0.001m, TransactionStatus.Pending, accountId, new BitcoinAddress(newAddress)); string withdrawTransactionId = coinClientService.CommitWithdraw(withdraw.BitcoinAddress.Value, withdraw.Amount); Assert.IsNotNull(withdrawTransactionId); Assert.IsFalse(string.IsNullOrEmpty(withdrawTransactionId)); manualResetEvent.WaitOne(); Assert.IsTrue(eventFired); depositAddress = depositAddressRepository.GetDepositAddressByAddress(bitcoinAddress); Assert.IsNotNull(depositAddress); Assert.AreEqual(AddressStatus.Used, depositAddress.Status); // See If DepositApplicationService created the deposit instance deposits = depositRepository.GetDepositsByBitcoinAddress(bitcoinAddress); Deposit deposit = deposits.Single(); Assert.IsNotNull(deposit); Assert.AreEqual(Amount, deposit.Amount); Assert.AreEqual(currency.Name, deposit.Currency.Name); Assert.IsFalse(string.IsNullOrEmpty(deposit.TransactionId.Value)); Assert.AreEqual(bitcoinAddress.Value, deposit.BitcoinAddress.Value); Assert.AreEqual(DepositType.Default, deposit.Type); Assert.AreEqual(0, deposit.Confirmations); Assert.AreEqual(accountId.Value, deposit.AccountId.Value); Assert.AreEqual(TransactionStatus.Pending, deposit.Status); Assert.AreEqual(withdrawTransactionId, deposit.TransactionId.Value); } }