public async Task Test_Withdraw_exceeded() { //Arrange var options = new DbContextOptionsBuilder <BankAppDbContext>() .UseInMemoryDatabase(databaseName: "Test_Withdraw_exceed") .Options; //Act using (var context = new BankAppDbContext(options)) { var account = new Account { Balance = 10, }; context.Accounts.Add(account); await context.SaveChangesAsync(); var x = new CreateWithdrawCommandHandler(context); await x.Handle(new CreateWithdrawCommand { Amount = 20, AccountId = account.AccountId }, new CancellationToken()); } //Assert that method throws AmountExceedsBalanceException }
public async Task Test_Transaction_Created() { //Arrange var options = new DbContextOptionsBuilder <BankAppDbContext>() .UseInMemoryDatabase(databaseName: "Test_Withdraw_exceed") .Options; int actual = 0; //Act using (var context = new BankAppDbContext(options)) { var senderAccount = new Account { Balance = 100, }; var recieverAccount = new Account { Balance = 0 }; context.AddRange(senderAccount, recieverAccount); await context.SaveChangesAsync(); var withdrawCommand = new CreateWithdrawCommandHandler(context); await withdrawCommand.Handle(new CreateWithdrawCommand { Amount = 10, AccountId = senderAccount.AccountId }, new CancellationToken()); var depositCommand = new CreateDepositCommandHandler(context); await depositCommand.Handle(new CreateDepositCommand { Amount = 10, AccountId = senderAccount.AccountId }, new CancellationToken()); var transferCommand = new CreateTransferCommandHandler(context); await transferCommand.Handle(new CreateTransferCommand { Amount = 10, SenderAccountId = senderAccount.AccountId, RecieverAccountId = recieverAccount.AccountId }, new CancellationToken()); actual = await context.Transactions.CountAsync(); } //Assert that method creates 4 transfers int expected = 4; Assert.AreEqual(expected, actual); }