Esempio n. 1
0
        public void WithdrawalMoney_SubstractAccountBalance()
        {
            //setup
            var dbContext = GetContext();

            var accRepo    = new AccountRepository(dbContext);
            var atmService = new AtmService(null, dbContext, accRepo);

            decimal balanceBefore = accRepo.GetAccount("A123456").Balance;

            //act
            bool result = atmService.WithdrawalMoney(120, "A123456");

            //assert
            decimal afterBalance = accRepo.GetAccount("A123456").Balance;

            Assert.True(result);
            Assert.Equal(balanceBefore - 120, afterBalance);
        }
Esempio n. 2
0
        public void WithdrawalMoney_SubstractAccountBalance_WithMock()
        {
            //setup
            var accRepoMock = new Mock <IAccountRepository>();

            accRepoMock.Setup(x => x.GetAccount("A123456")).Returns(new Account {
                Balance = 2000
            });

            var atmService = new AtmService(null, null, accRepoMock.Object);

            decimal balanceBefore = accRepoMock.Object.GetAccount("A123456").Balance;

            //act
            bool result = atmService.WithdrawalMoney(120, "A123456");

            //assert
            decimal afterBalance = accRepoMock.Object.GetAccount("A123456").Balance;

            Assert.True(result);
            Assert.Equal(balanceBefore - 120, afterBalance);
            accRepoMock.Verify(mock => mock.Update(It.IsAny <Account>()), Times.Once());
        }