Beispiel #1
0
        public void AccountBalanceDecreased_WhenUserWithdraws()
        {
            int accountId = 30;

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

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

            using (var context = new BankAppDataContext(options))
            {
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context);

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

                accountCommandHandler.Withdraw(accountId, withdrawalAmount);

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

                Assert.Less(balanceAfter, balanceBefore);
            }
        }
 public AccountCommandHandler(BankAppDataContext context, ISystemClock systemClock)
 {
     this.context = context;
     this.accountQueriesHandler      = new AccountQueriesHandler(context);
     this.transactionCommandsHandler = new TransactionCommandsHandler(context);
     this.systemClock = systemClock;
 }
 public AccountCommandHandler()
 {
     this.context = new BankAppDataContext();
     this.accountQueriesHandler      = new AccountQueriesHandler(context);
     this.transactionCommandsHandler = new TransactionCommandsHandler(context);
     this.systemClock = new SystemClock();
 }
Beispiel #4
0
 public IndexViewModel()
 {
     this.context          = new BankAppDataContext();
     this.Account_Queries  = new AccountQueriesHandler(context);
     this.Customer_Queries = new CustomerQueriesHandler(context);
     this.TotalCustomers   = Customer_Queries.GetCustomersList().Count;
     this.TotalAccounts    = Account_Queries.GetAllAccounts().Count;
     this.TotalBalance     = Account_Queries.CalculateTotalBalance();
 }
Beispiel #5
0
        public AccountViewModel(int accountId, int customerId)
        {
            this.context          = new BankAppDataContext();
            this.customer_queries = new CustomerQueriesHandler(context);
            this.account_queries  = new AccountQueriesHandler(context);

            Account  = account_queries.GetAccountWithTransactions(accountId);
            Customer = customer_queries.GetCustomer(customerId);
        }
Beispiel #6
0
        public void Setup()
        {
            options = new DbContextOptionsBuilder <BankAppDataContext>()
                      .UseInMemoryDatabase(databaseName: "TestingDb")
                      .Options;

            systemClock               = Substitute.For <ISystemClock>();
            context                   = new BankAppDataContext(options);
            accountQueriesHandler     = new AccountQueriesHandler(context);
            accountCommandHandler     = new AccountCommandHandler(context);
            customerCommandHandler    = new CustomerCommandHandler(context);
            customerQueriesHandler    = new CustomerQueriesHandler(context);
            dispositionQueriesHandler = new DispositionQueriesHandler(context);
        }
Beispiel #7
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));
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
 public WebAPIController()
 {
     accountQueriesHandler   = new AccountQueriesHandler();
     transactionQueryHandler = new TransactionQueryHandler();
     customerQueriesHandler  = new CustomerQueriesHandler();
 }