Example #1
0
        public void WithdrawWithBalancePositive()
        {
            var depositValue  = 50.5m;
            var withdrawValue = 10.2m;

            var expectedBalance = depositValue - withdrawValue;

            var hardwareMock = new HardwareMock(number, depositValue, withdrawValue);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();
            cashMachine.Deposit();

            var result = cashMachine.Withdraw();

            var balance = cashMachine.AccountBalance();

            hardwareMock.VerifyCalledMethod(HardwareMock.MethodGetValueToWithdraw, null, withdrawValue);
            serviceMock.VerifyCalledMethod(RemoteServiceMock.MethodPersitAccount, new object[] { account }, null, 2);

            Assert.AreEqual(string.Format(CourseraTDD.CashMachine.CashMachine.SuccessBalanceMessage, expectedBalance), balance);
            Assert.AreEqual(CourseraTDD.CashMachine.CashMachine.SuccessWithdrawMessage, result);
        }
Example #2
0
        public void LoginErrorWhenCantFindAccount()
        {
            var hardwareMock = new HardwareMock(number);

            var serviceMock = new RemoteServiceMock(account, RemoteServiceMock.Error.FindAccountInternal);
            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            Assert.Throws <FindAccountInternalException>(() => cashMachine.Login());
        }
Example #3
0
        public void LoginWithAccountNumberInvalid()
        {
            var hardwareMock = new HardwareMock(number);
            var serviceMock  = new RemoteServiceMock(account, RemoteServiceMock.Error.FindAccountNotExists);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);
            var result      = cashMachine.Login();

            hardwareMock.VerifyCalledMethod(HardwareMock.MethodGetCardNumber, null, number);
            serviceMock.VerifyCalledMethod(RemoteServiceMock.MethodFindAccount, new object[] { number });

            Assert.AreEqual(CourseraTDD.CashMachine.CashMachine.InvalidLoginMessage, result);
        }
Example #4
0
        public void RequestEmptyBalance()
        {
            var hardwareMock = new HardwareMock(number);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();

            var ballance = cashMachine.AccountBalance();

            Assert.AreEqual(string.Format(CourseraTDD.CashMachine.CashMachine.SuccessBalanceMessage, 0), ballance);
        }
Example #5
0
        public void DepositWithErrorInRemoteService()
        {
            var valueToDeposit = 100.5m;

            var hardwareMock = new HardwareMock(number, valueToDeposit);
            var serviceMock  = new RemoteServiceMock(account, RemoteServiceMock.Error.PersistAccount);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();

            Assert.Throws <AccountPersistenceException>(() => cashMachine.Deposit());
        }
Example #6
0
        public void DepositErrorWhenCantGetValueFromHardware()
        {
            var valueToDeposit = 100.5m;

            var hardwareMock = new HardwareMock(number, valueToDeposit, HardwareMock.Error.ValueToDeposit);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();

            Assert.Throws <ReadValueToDepositException>(() => cashMachine.Deposit());
        }
Example #7
0
        public void WithdrawWhenCantGetValueFromHardware()
        {
            var depositValue = 50.5m;

            var hardwareMock = new HardwareMock(number, depositValue, 0m, HardwareMock.Error.ValueToWithdraw);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();
            cashMachine.Deposit();

            Assert.Throws <ReadValueToWithdrawException>(() => cashMachine.Withdraw());
        }
Example #8
0
        public void LoginWithAccountNumberValid()
        {
            var hardwareMock = new HardwareMock(number);
            var serviceMock  = new RemoteServiceMock(account);

            var machine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            var result = machine.Login();

            hardwareMock.VerifyCalledMethod(HardwareMock.MethodGetCardNumber, null, number);
            serviceMock.VerifyCalledMethod(RemoteServiceMock.MethodFindAccount, new object[] { number }, account);

            Assert.AreEqual(cashMachine.CashMachine.SuccessLoginMessage, result);
        }
Example #9
0
        public void RequestBalanceWithValue()
        {
            var depositValue = 50.5m;

            var hardwareMock = new HardwareMock(number, depositValue);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();
            cashMachine.Deposit();

            var ballance = cashMachine.AccountBalance();

            Assert.AreEqual(string.Format(CourseraTDD.CashMachine.CashMachine.SuccessBalanceMessage, depositValue), ballance);
        }
Example #10
0
        public void WithdrawWithErrorInRemoteService()
        {
            var depositValue  = 50.5m;
            var withdrawValue = 10.2m;

            var hardwareMock = new HardwareMock(number, depositValue, withdrawValue);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();
            cashMachine.Deposit();

            serviceMock.SetError(RemoteServiceMock.Error.PersistAccount);

            Assert.Throws <AccountPersistenceException>(() => cashMachine.Withdraw());
        }
Example #11
0
        public void DepositAuthenticated()
        {
            var valueToDeposit = 100.5m;

            var hardwareMock = new HardwareMock(number, valueToDeposit);
            var serviceMock  = new RemoteServiceMock(account);

            var cashMachine = new cashMachine.CashMachine(hardwareMock, serviceMock);

            cashMachine.Login();

            var result = cashMachine.Deposit();

            hardwareMock.VerifyCalledMethod(HardwareMock.MethodGetValueToDeposit, null, valueToDeposit);
            serviceMock.VerifyCalledMethod(RemoteServiceMock.MethodPersitAccount, new object[] { account });

            Assert.AreEqual(CourseraTDD.CashMachine.CashMachine.SuccessDepositMessage, result);
        }