public async Task TestWalletDownloadWithoutReferral()
        {
            var dbContext = TestUtils.CreateDatabase();

            try
            {
                var ip = "1.1.1.1";
                TestUtils.RemoveOldDownloads(ip);
                var testUser = TestUtils.CreateTestUserWithoutRef("test", "auth0|test");

                TestUtils.GetBalances(testUser, out decimal? downloadStartBalance, out decimal? referralStartBalance);

                var controller = new WalletDownloadController(dbContext);
                var res        = await controller.Download(TestUtils.CreateDownload(ip, DateTime.Now, testUser), DateTime.Now);

                Assert.Equal(200, (res as StatusCodeResult).StatusCode);
                var dbContext2 = TestUtils.CreateDatabase();

                try
                {
                    TestUtils.GetBalances(testUser, out decimal? downloadEndBalance, out decimal? referralEndBalance);
                    Assert.Equal(downloadEndBalance, downloadStartBalance);
                    Assert.Equal(referralEndBalance, referralStartBalance);
                }
                finally
                {
                    dbContext2.Dispose();
                }
            }
            finally
            {
                dbContext.Dispose();
            }
        }
Exemplo n.º 2
0
        public static async Task TestWalletDownloadWithReferrerInternal(BitcornContext dbContext, string ip, User testUser, bool shouldCompleteBonus)
        {
            TestUtils.GetBalances(testUser, out decimal? downloadStartBalance, out decimal? referralStartBalance);
            var userReferral = dbContext.UserReferral.FirstOrDefault(u => u.UserId == testUser.UserId);
            var referrer     = dbContext.Referrer.FirstOrDefault(u => u.ReferralId == userReferral.ReferralId);
            var controller   = new WalletDownloadController(dbContext);
            var res          = await controller.Download(TestUtils.CreateDownload(ip, DateTime.Now, testUser, referrer.UserId), DateTime.Now);

            Assert.Equal(200, (res as StatusCodeResult).StatusCode);

            var dbContext2 = TestUtils.CreateDatabase();

            try
            {
                var referralPayoutTotal = await ReferralUtils.TotalReward(dbContext, referrer) + await ReferralUtils.WalletBonusReward(dbContext, referrer, 10);;

                TestUtils.GetBalances(testUser, out decimal? downloadEndBalance, out decimal? referralEndBalance);
                decimal bonus = 0;
                if (shouldCompleteBonus)
                {
                    bonus = ReferralUtils.BONUS_PAYOUT;
                }
                Assert.Equal(referralStartBalance + referralPayoutTotal + bonus, referralEndBalance);
                Assert.Equal(downloadStartBalance + 10 + referrer.Amount + bonus, downloadEndBalance);
            }
            finally
            {
                dbContext2.Dispose();
            }
        }
        async Task TestMultiWalletDownload(DateTime otherTime, bool expectSuccess)
        {
            var dbContext = TestUtils.CreateDatabase();

            try
            {
                var controller = new WalletDownloadController(dbContext);

                var ip = "1.1.1.1";
                TestUtils.RemoveOldDownloads(ip);

                var testUser = TestUtils.CreateTestUser("test", "auth0|test", 2);

                await controller.Download(TestUtils.CreateDownload(ip, DateTime.Now, testUser), DateTime.Now);

                var testUser2 = TestUtils.CreateTestUser("test", "auth0|test2", 2);
                var downloads = dbContext.WalletDownload.Where(d => d.IPAddress == ip).ToArray();
                TestUtils.GetBalances(testUser2, out decimal? downloadStartBalance, out decimal? referralStartBalance);
                var res = await controller.Download(TestUtils.CreateDownload(ip, otherTime, testUser2), otherTime);

                Assert.Equal(200, (res as StatusCodeResult).StatusCode);
                TestUtils.GetBalances(testUser2, out decimal? downloadEndBalance, out decimal? referralEndBalance);
                if (!expectSuccess)
                {
                    Assert.Equal(downloadEndBalance, downloadStartBalance);
                    Assert.Equal(referralEndBalance, referralStartBalance);
                }
                else
                {
                    Assert.True(downloadEndBalance > downloadStartBalance);
                    Assert.True(referralEndBalance > referralStartBalance);
                }
            }
            finally
            {
                dbContext.Dispose();
            }
        }