Exemplo n.º 1
0
        public async Task DailyStreakResetTest()
        {
            await using var unit = NewContext();
            var userService        = new UserService(unit, null);
            var transactionService = new TransactionService(userService);
            var dailyService       = new DailyService(unit, userService, transactionService);

            await dailyService.ClaimDailyAsync(4L);

            var daily = await dailyService.GetOrCreateDailyAsync(4L);

            Assert.Equal(0, daily.CurrentStreak);
        }
Exemplo n.º 2
0
        public async Task ClaimDailyTest()
        {
            await using var unit = NewContext();
            var userService        = new UserService(unit, null);
            var transactionService = new TransactionService(userService);
            var dailyService       = new DailyService(unit, userService, transactionService);

            var response = await dailyService.ClaimDailyAsync(2L);

            Assert.NotNull(response);
            Assert.Equal(1, response.CurrentStreak);
            Assert.Equal(1, response.LongestStreak);
            Assert.Equal(120, response.AmountClaimed);
            Assert.InRange(
                response.LastClaimTime, DateTime.UtcNow.AddMinutes(-2), DateTime.UtcNow.AddMinutes(2));
        }
Exemplo n.º 3
0
        public async Task CheckIfDailyUpdatedInDatabaseTest()
        {
            await using var unit = NewContext();
            var userService        = new UserService(unit, null);
            var transactionService = new TransactionService(userService);
            var dailyService       = new DailyService(unit, userService, transactionService);

            await dailyService.ClaimDailyAsync(2L);

            var daily = await dailyService.GetOrCreateDailyAsync(2L);

            Assert.NotNull(daily);
            Assert.Equal(1, daily.CurrentStreak);
            Assert.Equal(1, daily.LongestStreak);
            Assert.InRange(daily.LastClaimTime, DateTime.UtcNow.AddMinutes(-2), DateTime.UtcNow.AddMinutes(2));
        }
Exemplo n.º 4
0
        public async Task DonatorClaimDailyTest()
        {
            await using var unit = NewContext();
            var userService        = new UserService(unit, null);
            var transactionService = new TransactionService(userService);
            var dailyService       = new DailyService(unit, userService, transactionService);

            var response = await dailyService.ClaimDailyAsync(3L);

            var expectedClaimAmount = (AppProps.Daily.DailyAmount + AppProps.Daily.StreakAmount * 6) * 2;

            Assert.NotNull(response);
            Assert.Equal(6, response.CurrentStreak);
            Assert.Equal(10, response.LongestStreak);
            Assert.Equal(expectedClaimAmount, response.AmountClaimed);
            Assert.InRange(response.LastClaimTime, DateTime.UtcNow.AddMinutes(-2), DateTime.UtcNow.AddMinutes(2));
        }
Exemplo n.º 5
0
        public async Task HigherThanHundredDailyTest()
        {
            await using var unit = NewContext();

            var userServiceMock = new Mock <IUserService>();

            userServiceMock.Setup(x => x.GetUserAsync(It.IsAny <long>()))
            .Returns(new ValueTask <User>(new User {
                Id = 5L
            }));
            var transactionServiceMock = new Mock <ITransactionService>();

            transactionServiceMock.Setup(x => x.CreateTransactionAsync(It.IsAny <TransactionRequest>()))
            .Returns(Task.FromResult(new TransactionResponse(null, null, 0)));

            var dailyService = new DailyService(
                unit, userServiceMock.Object, transactionServiceMock.Object);

            var dailyResponse = await dailyService.ClaimDailyAsync(5L);

            Assert.Equal(2100, dailyResponse.AmountClaimed);
        }