Exemplo n.º 1
0
        public IActionResult ApplyInterest(InterestViewModel model)
        {
            var command = new ApplyInterestCommand {
                AccountId = 1, Amount = 1, PreviousApplication = DateTime.Parse("2018-05-28")
            };
            var handler = new ApplyInterestHandler(new BankContext());

            handler.Handler(command);

            TempData["success"] = "Interest applied succesfully";
            return(View());
        }
Exemplo n.º 2
0
        public void Interest_ApplyTest()
        {
            var date = new DateTime();

            date.SetTime("2018-05-28");

            var options = new DbContextOptionsBuilder <BankContext>()
                          .UseInMemoryDatabase(databaseName: "NegativeAmount")
                          .Options;

            using (var context = new BankContext(options))
            {
                var account = new Account
                {
                    AccountId = 7,
                    Frequency = "Weekly",
                    Balance   = 1000
                };

                context.Accounts.Add(account);
                context.SaveChanges();
            }

            using (var context = new BankContext(options))
            {
                var command = new ApplyInterestCommand {
                    AccountId = 7, Amount = 1, PreviousApplication = date.Parse("2018-05-28")
                };
                var handler = new ApplyInterestHandler(context);
                handler.Handler(command);

                var account = context.Accounts.SingleAsync(x => x.AccountId == 7).Result;

                Assert.Equal(1010.0492M, Math.Round(account.Balance, 4), 4);
            }
        }