예제 #1
0
        public void Deposit_InvoiceExists_ThrowsException()
        {
            var user    = UserFaker.Create();
            var invoice = InvoiceFaker.Create(user, user.id, EntityType.UserBalance);

            Assert.IsNull(FundingTransactionRepository.Find(user, invoice, user.id, EntityType.UserBalance));

            FundingTransactionRepository.CreateDeposit(user, invoice);

            Assert.Throws <Exception>(
                () => { UserBalanceUtils.Deposit(user, invoice); });
        }
        public void Create_DataCorrect_GotCorrectId()
        {
            var user = UserFaker.Create();

            var project = ProjectFaker.Create(user);

            var invoice = InvoiceFaker.Create(user);

            var id = FundingTransaction.Create(
                user, project.id, EntityType.Project, invoice, 0.05M, CurrencyType.BitCoin
                );

            Assert.True(id > 0);

            var tx = FundingTransactionRepository.Find(id);

            Assert.NotNull(tx);
        }
예제 #3
0
        public void Deposit_DataCorrect_BalanceIncreasedAndTxCreated()
        {
            var user    = UserFaker.Create();
            var invoice = InvoiceFaker.Create(user, user.id, EntityType.UserBalance);

            Assert.IsNull(FundingTransactionRepository.Find(user, invoice, user.id, EntityType.UserBalance));

            var balance = UserBalanceUtils.Deposit(user, invoice);

            var tx = FundingTransactionRepository.Find(user, invoice, user.id, EntityType.UserBalance);

            Assert.IsNotNull(tx);

            Assert.AreEqual(user.id, tx.entity_id);
            Assert.AreEqual(user.id, tx.from_user_id);
            Assert.AreEqual(EntityType.UserBalance, tx.entity_type);

            Assert.AreEqual(invoice.amount, balance.balance);
        }
예제 #4
0
        public static UserBalance Deposit(User user, Invoice invoice)
        {
            if (invoice.entity_type != EntityType.UserBalance)
            {
                throw new Exception("Deposit can be done only for UserBalance");
            }

            var existingTx = FundingTransactionRepository.Find(user, invoice, user.id, EntityType.UserBalance);

            var balance = UserBalanceRepository.FindOrCreate(invoice);

            if (existingTx != null)
            {
                throw new Exception("Transaction for specified invoice already exists");
            }

            FundingTransactionUtils.CreateTxFromInvoice(invoice);
            UserBalanceRepository.UpdateBalance(balance, balance.balance + invoice.amount);

            return(balance.Refresh());
        }
예제 #5
0
        public void Deposit_2Deposits_SumCorrect()
        {
            var user    = UserFaker.Create();
            var invoice = InvoiceFaker.Create(user, user.id, EntityType.UserBalance);

            Assert.IsNull(FundingTransactionRepository.Find(user, invoice, user.id, EntityType.UserBalance));

            var balance = UserBalanceUtils.Deposit(user, invoice);

            var tx = FundingTransactionRepository.Find(user, invoice, user.id, EntityType.UserBalance);

            Assert.IsNotNull(tx);

            Assert.AreEqual(invoice.amount, balance.balance);

            var invoice2 = InvoiceFaker.Create(user, user.id, EntityType.UserBalance);

            balance = UserBalanceUtils.Deposit(user, invoice2);

            Assert.AreEqual(invoice.amount + invoice2.amount, balance.balance);
        }