예제 #1
0
        public void TestLastDateCalculation()
        {
            SavingsDeposit deposit = new SavingsDeposit
            {
                Owner                    = _user.Id,
                StartDate                = DateTime.Today,
                EndDate                  = DateTime.Today.AddDays(2),
                InitialAmount            = 100_000,
                TaxPercentage            = 15,
                YearlyInterestPercentage = 5
            };

            _context.SavingsDeposits.Add(deposit);
            _context.Users.Add(_user);
            _context.SaveChanges();

            //if entity is added today, then calculation will be at night next day, so its
            //needed to check if the calculation will be perfomed at night of end date + 1
            foreach (var date in new[]
            {
                DateTime.Today.AddDays(1), DateTime.Today.AddDays(2), DateTime.Today.AddDays(3),
                DateTime.Today.AddDays(3), DateTime.Today.AddDays(4)
            })
            {
                _calculationService.RunCalculationForAllUsersAsync(date).Wait();
            }

            DepositHistory[] result = _context.DepositsHistory.ToArray();

            Assert.Equal(3, result.Length);
            Assert.Equal(11.81m * 3, result.Last().TotalProfitAfterTax);
        }
예제 #2
0
        private void SeedWithData(AppDataContext context, UserManager <User> userManager)
        {
            var root = userManager.Users.FirstOrDefault(x => x.UserName == "admin");

            if (root == null)
            {
                root = new User
                {
                    Id       = "myId",
                    UserName = "******",
                    Email    = "*****@*****.**",
                    FullName = "Great Root"
                };
                var res = userManager.CreateAsync(root, "Admin1@#").Result;
                res = userManager.AddToRoleAsync(root, "ADMIN").Result;
            }


            if (!context.SavingsDeposits.Any(x => x.Owner == "myId"))
            {
                try
                {
                    context.SavingsDeposits.AddRange(TestData());
                    context.SaveChanges();

                    SavingsComputationService computationService = new SavingsComputationService(context);
                    for (int i = 0; i < 7; i++)
                    {
                        computationService.RunCalculationForAllUsersAsync(DateTime.Now.AddDays(i)).Wait();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }