public void TestSavingsDepositsCalculation() { var calculationService = new SavingsComputationService(null); SavingsDeposit savingsDeposit = new SavingsDeposit { InitialAmount = 100_000, TaxPercentage = 15, YearlyInterestPercentage = 5 }; DepositHistory depositHistory = calculationService.PerformDepositCalculation(savingsDeposit); savingsDeposit.CurrentProfitAfterTax = depositHistory.TotalProfitAfterTax; savingsDeposit.LastCalculation = DateTime.Today; depositHistory.CalculationDate = DateTime.Today; Assert.Equal(13.89m, depositHistory.ProfitBeforeTax); Assert.Equal(2.08m, depositHistory.ProfitTax); Assert.Equal(11.81m, depositHistory.ProfitAfterTax); Assert.Equal(11.81m, depositHistory.TotalProfitAfterTax); depositHistory = calculationService.PerformDepositCalculation(savingsDeposit); savingsDeposit.CurrentProfitAfterTax = depositHistory.TotalProfitAfterTax; savingsDeposit.LastCalculation = DateTime.Today; depositHistory.CalculationDate = DateTime.Today; Assert.Equal(13.89m, depositHistory.ProfitBeforeTax); Assert.Equal(2.08m, depositHistory.ProfitTax); Assert.Equal(11.81m, depositHistory.ProfitAfterTax); Assert.Equal(23.62m, depositHistory.TotalProfitAfterTax); SavingsDeposit credit = new SavingsDeposit { InitialAmount = 100_000, TaxPercentage = 15, YearlyInterestPercentage = -20 }; depositHistory = calculationService.PerformDepositCalculation(credit); Assert.Equal(-55.56m, depositHistory.ProfitBeforeTax); Assert.Equal(depositHistory.ProfitBeforeTax, depositHistory.ProfitAfterTax); Assert.Equal(0m, depositHistory.ProfitTax); }
public ComputationTest() { var options = new DbContextOptionsBuilder <AppDataContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; _context = new AppDataContext(options); _user = new User { Id = "myId", UserName = "******", FullName = "Big Dummy", Email = "*****@*****.**" }; _context.Users.Add(_user); _calculationService = new SavingsComputationService(_context); }
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); } } }