/// <summary> /// Mocking the context using in memory database with 4 accounts. /// Accounts ID 1-5. ID 5 has a balance of 100 000 and 1-4 500 /// The tests are depending on the mocked accounts. /// Don't change the balance directly in this method. /// </summary> /// <returns>BankAppDataContext</returns> public static BankAppDataContext Get() { var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new BankAppDataContext(options); var accounts = new[] { new Account { AccountId = 1, Balance = 500m, Frequency = "Monthly", Created = DateTime.Now }, new Account { AccountId = 2, Balance = 500m, Frequency = "Monthly", Created = DateTime.Now }, new Account { AccountId = 3, Balance = 500m, Frequency = "Monthly", Created = DateTime.Now }, new Account { AccountId = 4, Balance = 500m, Frequency = "Monthly", Created = DateTime.Now }, new Account { AccountId = 5, Balance = 100000m, Frequency = "Monthly", Created = DateTime.Now }, }; context.Accounts.AddRange(accounts); context.SaveChanges(); return(context); }
public void Transfer_CantTransferNegativeAmounts() { using (var context = new BankAppDataContext(_options)) { // Arrange int accountIdFrom = 56789; int accountIdTo = 67890; Account temporaryFromAccount = new Account(); temporaryFromAccount.Balance = 500.00m; temporaryFromAccount.AccountId = accountIdFrom; decimal expectedFrom = temporaryFromAccount.Balance; Account temporaryToAccount = new Account(); temporaryToAccount.Balance = 300.00m; temporaryToAccount.AccountId = accountIdTo; decimal expectedTo = temporaryToAccount.Balance; // Saving the account to DB context.Accounts.Add(temporaryFromAccount); context.Accounts.Add(temporaryToAccount); context.SaveChanges(); decimal transferAmount = -800.00m; // Act Action act = () => { new CreateTransaction(context).Transfer(accountIdFrom, accountIdTo, transferAmount); }; var fromAcc = context.Accounts.Where(a => a.AccountId == accountIdFrom).SingleOrDefault(); var toAcc = context.Accounts.Where(a => a.AccountId == accountIdTo).SingleOrDefault(); // Assert Assert.Equal(expectedFrom, fromAcc.Balance); Assert.Equal(expectedTo, toAcc.Balance); } }
[Fact] // TODO public void Withdrawal_CantWithdrawNegativeAmounts() { using (var context = new BankAppDataContext(_options)) { int accountId = 23456; // Arrange Account temporaryAccount = new Account(); temporaryAccount.Balance = 500.00m; temporaryAccount.AccountId = accountId; decimal expectedBalance = temporaryAccount.Balance; // Saving the account to DB context.Accounts.Add(temporaryAccount); context.SaveChanges(); decimal withdrawalAmount = -300.00m; // Act Action act = () => { new AccountHandler().Withdrawal(accountId, withdrawalAmount, context); }; // Assert var account = context.Accounts.Where(a => a.AccountId == accountId).SingleOrDefault(); Assert.Equal(expectedBalance, account.Balance); } }
static void Main(string[] args) { using (var context = new BankAppDataContext()) { var stopWatch = new Stopwatch(); stopWatch.Start(); //var kunder = context.Customers.Take(1000).ToList(); var kunder = context.Customers .Include(c => c.Dispositions) .ThenInclude(d => d.Account) .Take(1000).ToList(); foreach (var kund in kunder) { Console.WriteLine($"{kund.CustomerId} {kund.Givenname} {kund.Surname}"); foreach (var disposition in kund.Dispositions) { Console.WriteLine($"{disposition.AccountId} {disposition.Account.Created} {disposition.Account.Frequency}"); } } stopWatch.Stop(); Console.WriteLine($"Tid: {stopWatch.Elapsed}ms"); } }
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 BankController(BankAppDataContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager) { _context = context; _userManager = userManager; _signInManager = signInManager; }
public AccountCommandHandler(BankAppDataContext context, ISystemClock systemClock) { this.context = context; this.accountQueriesHandler = new AccountQueriesHandler(context); this.transactionCommandsHandler = new TransactionCommandsHandler(context); this.systemClock = systemClock; }
public async Task CreateTransactionsRight_Tests(decimal amount, string type) { var command = new CreateTransactionCommand() { AccountId = 1, Amount = amount, Type = type }; var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "CreateTransactionsRight_Tests") .Options; using (var context = new BankAppDataContext(options)) { await context.AddAsync(new Account() { AccountId = 1, Balance = 1000 }); await context.SaveChangesAsync(CancellationToken.None); var handler = new CreateTransactionCommandHandler(context); var result = await handler.Handle(command, CancellationToken.None); decimal expected = 1100; var account = await context.Accounts.SingleOrDefaultAsync(a => a.AccountId == 1); var transactions = await context.Accounts.Include(a => a.Transactions).SingleOrDefaultAsync(a => a.AccountId == 1); var count = transactions.Transactions.Count(); var actual = account.Balance; Assert.Equal(expected, actual); Assert.Equal(1, count); } }
public void Deposit_CantDepositwNegativeAmounts() { using (var context = new BankAppDataContext(_options)) { // Arrange int accountId = 78901; Account temporaryAccount = new Account(); temporaryAccount.Balance = 500.00m; temporaryAccount.AccountId = accountId; decimal expected = temporaryAccount.Balance; // Saving the account to DB context.Accounts.Add(temporaryAccount); context.SaveChanges(); decimal amount = -800.00m; // Act & Assert Action act = () => { bool actual = new AccountHandler().Deposit(accountId, amount, context); Assert.False(actual); }; var account = context.Accounts.Where(a => a.AccountId == temporaryAccount.AccountId).SingleOrDefault(); // Assert Assert.Equal(expected, account.Balance); } }
public AccountCommandHandler() { this.context = new BankAppDataContext(); this.accountQueriesHandler = new AccountQueriesHandler(context); this.transactionCommandsHandler = new TransactionCommandsHandler(context); this.systemClock = new SystemClock(); }
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); }
public CustomerProfile(int customerId) { this.context = new BankAppDataContext(); this.customer_queries = new CustomerQueriesHandler(context); this.disposition_queries = new DispositionQueriesHandler(context); Customer = customer_queries.GetCustomer(customerId); this.ConnectedDispositions = disposition_queries.GetConnectedDispositions(Customer.CustomerId); }
public EditCustomerViewModel(int id) { this.context = new BankAppDataContext(); this.customerCommandHandler = new CustomerCommandHandler(context); this.customerQueriesHandler = new CustomerQueriesHandler(context); Customer = customerQueriesHandler.GetCustomer(id); Birthday = (DateTime)Customer.Birthday; }
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(); }
public BaseTest() { var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .EnableSensitiveDataLogging() .Options; ctxInMemmory = new BankAppDataContext(options); fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => fixture.Behaviors.Remove(b)); fixture.Behaviors.Add(new OmitOnRecursionBehavior(1)); }
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); }
private void UploadDocuments(ISearchIndexClient indexClient) { BankAppDataContext context = new BankAppDataContext(); var searchCustomer = context.Customers.Select(c => new SearchCustomer { CustomerId = c.CustomerId, Id = c.CustomerId.ToString(), NationalId = c.NationalId, Name = c.Givenname + " " + c.Surname, Address = c.Streetaddress, City = c.City }).ToArray(); var batch = IndexBatch.Upload(searchCustomer); indexClient.Documents.Index(batch); }
public void Setup() { var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; _context = new BankAppDataContext(options); if (_context.Accounts.FirstOrDefault(x => x.AccountId == 2) == null) { _context.Accounts.Add(new Accounts { AccountId = 2, Balance = 100 }); _context.SaveChanges(); } _sut = new InsertService(_context); }
public async Task CreateTransfer_Tests(decimal amount, int fromacc, int toacc) { var command = new CreateTransferCommand() { Amount = amount, FromAccountId = fromacc, ToAccountId = toacc }; var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "CreateTransfer_Tests") .Options; using (var context = new BankAppDataContext(options)) { var handler = new CreateTransferCommandHandler(context); var result = await handler.Handle(command, CancellationToken.None); Assert.False(result.Success); } }
public async Task AddInterest_Tests(decimal yearlyint, int accountid) { var account = new Account() { AccountId = 1, Balance = 10000 }; var command = new AddInterestCommand() { AccountId = accountid, YearlyInterest = yearlyint, LatestInterest = DateTime.Now }; var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "AddInterest_Tests") .Options; decimal expected; using (var context = new BankAppDataContext(options)) { context.Add(new Account() { AccountId = 1, Balance = 10000 }); context.SaveChanges(); var machine = new MachineDateTime() { }; machine.Now = machine.Now.AddDays(30); var handler = new AddInterestCommandHandler(context, machine); expected = 10039.73m; await handler.Handle(command, CancellationToken.None); var newbalance = await context.Accounts.SingleOrDefaultAsync(a => a.AccountId == 1); var test = Math.Round(newbalance.Balance, 2); Assert.Equal(expected, test); } }
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)); } }
public void Setup() { var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "BankAppData") .Options; _context = new BankAppDataContext(options); if (_context.Accounts.FirstOrDefault(x => x.AccountId == 1) == null) { _context.Accounts.Add(new Accounts { AccountId = 1, Balance = 100 }); _context.SaveChanges(); } Mock <IAccountService> mockedAccountService = new Mock <IAccountService>(); mockedAccountService.Setup(x => x.GetAccountBalanceByID(It.IsAny <int>())).Returns(100m); _sut = new WithdrawService(_context, mockedAccountService.Object); }
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); } }
public async Task CreateTransaction_Tests(decimal amount, string type) { var command = new CreateTransactionCommand() { AccountId = 1, Amount = amount, Type = type }; var options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "CreateTransaction_Tests") .Options; using (var context = new BankAppDataContext(options)) { context.Accounts.Add(new Account() { AccountId = 1, Balance = 1000 }); var handler = new CreateTransactionCommandHandler(context); var result = await handler.Handle(command, CancellationToken.None); Assert.False(result.Success); } }
public CustomerRepository(BankAppDataContext context) { _context = context; }
public TransactionRepository(BankAppDataContext context) { _context = context; }
public EditCustomerViewModel() { this.context = new BankAppDataContext(); this.customerCommandHandler = new CustomerCommandHandler(context); this.customerQueriesHandler = new CustomerQueriesHandler(context); }
public Repository(BankAppDataContext Context) { _context = Context; }
public LoginRepository(BankAppDataContext context, UserManager <IdentityUser> userManager) { _context = context; }
public InsertService(BankAppDataContext context) { _context = context; }