예제 #1
0
        public void Create_DataCorrect_BalanceAndTransactionCreated()
        {
            var invoice = InvoiceFaker.Create();

            var balance = FundingBalanceRepository.Create(
                invoice.entity_id, invoice.entity_type, invoice.currency_type
                );

            FundingBalanceRepository.AddFunds(balance, invoice);

            Assert.NotNull(balance);

            var txs = FundingTransactionRepository.Get(invoice.entity_id, invoice.entity_type, invoice.currency_type);

            Assert.AreEqual(1, txs.Length);

            var transaction = txs[0];

            balance = balance.Refresh();

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

            Assert.AreEqual(balance.entity_id, transaction.entity_id);
            Assert.AreEqual(balance.entity_type, transaction.entity_type);
            Assert.AreEqual(balance.currency_type, transaction.currency_type);
        }
예제 #2
0
        public RegisterBonus()
        {
            Post("/api/v1/schedule/user/register_bonus/start", _ => {
                var task = Task.Run(() => {
                    int tokenBonus = Convert.ToInt32(
                        AppConfig.GetConfiguration("user:registration:token_bonus")
                        );
                    if (tokenBonus <= 0)
                    {
                        return;
                    }

                    int pageIndex = 1;
                    var users     = DL.Model.User.User.Paginate(pageIndex, 100);
                    while (users.Length > 0)
                    {
                        foreach (var user in users)
                        {
                            try {
                                if (
                                    !user.EmailConfirmed() || FundingTransactionRepository.Get(user).Length > 0
                                    )
                                {
                                    continue;
                                }
                                var balance = UserBalanceRepository.FindOrCreate(user, CurrencyType.GitComToken);
                                balance.UpdateBalance(balance.balance + tokenBonus);
                                FundingTransactionRepository.Create(
                                    user, user.id, EntityType.UserBalance, 2M, CurrencyType.GitComToken,
                                    "Registration bonus"
                                    );
                            }
                            catch (Exception e) {
                                SentrySdk.CaptureException(e);
                            }
                        }

                        ++pageIndex;
                        users = DL.Model.User.User.Paginate(pageIndex, 100);
                    }
                });
                JobsPool.Get().Push(task);
                return(HttpResponse.Data(new JObject()));
            });
        }
예제 #3
0
        public void FundEntity_DataCorrect_EntityFundedTxCreated()
        {
            var user = UserFaker.Create();

            var project = ProjectFaker.Create();

            var amount = Rand.SmallDecimal();

            var balance =
                SubscriptionFundingUtils.FundEntity(user, project.id, EntityType.Project, amount, CurrencyType.BitCoin);

            Assert.AreEqual(amount, balance.balance);

            var txs = FundingTransactionRepository.Get(project.id, EntityType.Project, CurrencyType.BitCoin);

            Assert.AreEqual(1, txs.Length);
            Assert.AreEqual(amount, txs[0].amount);
        }
예제 #4
0
        public void RegisterBonus_Ok()
        {
            var user = UserFaker.Create();

            var browser = new Browser(new DefaultNancyBootstrapper());
            var result  = browser
                          .Post("/api/v1/schedule/user/register_bonus/start", with => {
                with.HttpRequest();
                with.Query("schedule_token", AppConfig.GetConfiguration("auth:schedule:token"));
            }).Result;

            Assert.Zero(FundingTransactionRepository.Get(user).Length);

            JobsPool.Get().WaitAll();

            Assert.True(FundingTransactionRepository.Get(user).Length == 1);
            var balance    = UserBalanceRepository.Find(user, CurrencyType.GitComToken);
            var tokenBonus = System.Convert.ToInt32(AppConfig.GetConfiguration("user:registration:token_bonus"));

            Assert.AreEqual(tokenBonus, balance.balance);
        }
        public void FundEntity_DataCorrect_EntityFunded()
        {
            var user = UserFaker.Create();

            var amount = Rand.SmallDecimal();

            var balance = UserBalanceRepository.FindOrCreate(user, CurrencyType.BitCoin);

            balance.UpdateBalance(amount);

            var info = UserSubscriptionInfoRepository.FindOrCreate(user);

            info.UpdateSelectedAmount(amount).Refresh();

            ProjectFaker.Create();

            SubscriptionUtils.PeriodPay(user);

            var txs = FundingTransactionRepository.Get(user);

            Assert.True(txs.Length > 0);
            Assert.True(txs[0].amount > 0);
        }