public void SaveWithdrawAddressesAndRetreiveByAccountIdTest_SavesMultipleObjectsToDatabase_ChecksIfRetreivedOutputIsAsExpected()
        {
            WithdrawAddress withdrawAddress = new WithdrawAddress(new Currency("XBT", true), new BitcoinAddress("iambitcoin123"), "Description is for dummies",
                                                                  new AccountId(1), DateTime.Now);

            _persistanceRepository.SaveOrUpdate(withdrawAddress);

            WithdrawAddress deposit2 = new WithdrawAddress(new Currency("XBT", true), new BitcoinAddress("321nioctibmai"), "Description is for champs",
                                                           new AccountId(1), DateTime.Now);

            Thread.Sleep(500);

            _persistanceRepository.SaveOrUpdate(deposit2);

            List <WithdrawAddress> retrievedWithdrawAddressList = _withdrawAddressRepository.GetWithdrawAddressByAccountId(new AccountId(1));

            Assert.IsNotNull(retrievedWithdrawAddressList);
            Assert.AreEqual(2, retrievedWithdrawAddressList.Count);

            Assert.AreEqual(withdrawAddress.BitcoinAddress.Value, retrievedWithdrawAddressList[0].BitcoinAddress.Value);
            Assert.AreEqual(withdrawAddress.Description, retrievedWithdrawAddressList[0].Description);
            Assert.AreEqual(withdrawAddress.AccountId.Value, retrievedWithdrawAddressList[0].AccountId.Value);

            Assert.AreEqual(deposit2.BitcoinAddress.Value, retrievedWithdrawAddressList[1].BitcoinAddress.Value);
            Assert.AreEqual(deposit2.Description, retrievedWithdrawAddressList[1].Description);
            Assert.AreEqual(deposit2.AccountId.Value, retrievedWithdrawAddressList[1].AccountId.Value);
        }
예제 #2
0
        /// <summary>
        /// Add new Address
        /// </summary>
        /// <param name="addAddressCommand"></param>
        /// <returns></returns>
        public WithdrawAddressResponse AddAddress(AddAddressCommand addAddressCommand)
        {
            if (addAddressCommand.BitcoinAddress.Length < 26 || addAddressCommand.BitcoinAddress.Length > 34)
            {
                return(new WithdrawAddressResponse(false, "Invalid address"));
            }
            List <WithdrawAddress> withdrawAddresses = _withdrawAddressRepository.GetWithdrawAddressByAccountIdAndCurrency(
                new AccountId(addAddressCommand.AccountId), new Currency(addAddressCommand.Currency));

            foreach (var address in withdrawAddresses)
            {
                if (address.BitcoinAddress.Value == addAddressCommand.BitcoinAddress ||
                    address.Description == addAddressCommand.Description)
                {
                    return(new WithdrawAddressResponse(false, "Duplicate Entry"));
                }
            }
            // Create a new address and save in the database
            WithdrawAddress withdrawAddress = new WithdrawAddress(new Currency(addAddressCommand.Currency),
                                                                  new BitcoinAddress(addAddressCommand.BitcoinAddress), addAddressCommand.Description,
                                                                  new AccountId(addAddressCommand.AccountId), DateTime.Now);

            _fundsPersistenceRepository.SaveOrUpdate(withdrawAddress);

            DepositAddress depositAddress = _depositAddressRepository.GetDepositAddressByAddress(new BitcoinAddress(addAddressCommand.BitcoinAddress));

            if (depositAddress != null)
            {
                depositAddress.StatusUsed();
                _fundsPersistenceRepository.SaveOrUpdate(depositAddress);
            }
            return(new WithdrawAddressResponse(true, "Address Saved"));
        }