예제 #1
0
        public IActionResult ApplyInterest(int accountId, double rate, DateTime lastTimeApplied)
        {
            if (ModelState.IsValid)
            {
                int result = accountHandler.ApplyInterest(accountId, rate, lastTimeApplied);

                if (result == 1)
                {
                    TempData["success"] = "Operation executed successfully.";

                    return(View());
                }
            }

            TempData["error"] = "Operation was unsuccessful. Please check that rate and account Id are correct.";


            return(View());
        }
예제 #2
0
        public void InterestIsCorrectlyApplied_WhenUserActivatesInterest()
        {
            int accountId = 78;

            options = new DbContextOptionsBuilder <BankAppDataContext>()
                      .UseInMemoryDatabase(databaseName: "TestingDb")
                      .Options;
            using (var context = new BankAppDataContext(options))
            {
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context, systemClock);

                context.Accounts.Add(new Account {
                    AccountId = accountId, Balance = 2000
                });
                context.SaveChanges();
            }

            using (var context = new BankAppDataContext(options))
            {
                var systemClock = Substitute.For <ISystemClock>();
                systemClock.GetCurrentTime().Returns(new DateTime(2020, 4, 4, 14, 0, 0, DateTimeKind.Utc));
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context, systemClock);

                decimal balanceBefore = accountQueriesHandler.GetAccount(accountId).Balance;

                double rate = 2;

                DateTime latestInterestDate = new DateTime(2018, 02, 02);
                var      currentDate        = new DateTime(2020, 4, 4, 14, 0, 0, DateTimeKind.Utc);

                accountCommandHandler.ApplyInterest(accountId, rate, latestInterestDate);

                decimal balanceAfter = accountQueriesHandler.GetAccount(accountId).Balance;
                double  days         = (currentDate - latestInterestDate).TotalDays;

                Assert.AreEqual(balanceAfter, Decimal.Round(balanceBefore + (decimal)((double)balanceBefore * rate / 100 / 365 * days), 2));
            }
        }
예제 #3
0
        public void TransactionIsCreated_WhenUserAppliesInterest()
        {
            int accountId = 77;

            options = new DbContextOptionsBuilder <BankAppDataContext>()
                      .UseInMemoryDatabase(databaseName: "TestingDb")
                      .Options;
            using (var context = new BankAppDataContext(options))
            {
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context, systemClock);

                context.Accounts.Add(new Account {
                    AccountId = accountId, Balance = 2000
                });
                context.SaveChanges();
            }

            using (var context = new BankAppDataContext(options))
            {
                var systemClock = Substitute.For <ISystemClock>();
                systemClock.GetCurrentTime().Returns(new DateTime(2020, 4, 4, 14, 0, 0, DateTimeKind.Utc));
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context, systemClock);

                int allTransactionsBefore = context.Transactions.CountAsync().Result;

                double   rate = 0.02;
                DateTime latestInterestDate = new DateTime(2018, 02, 02);
                var      currentDate        = DateTime.Now;
                accountCommandHandler.ApplyInterest(accountId, rate, latestInterestDate);

                int allTransactionsAfter = context.Transactions.CountAsync().Result;

                Assert.AreEqual(allTransactionsAfter, allTransactionsBefore + 1);
            }
        }