コード例 #1
0
        public void StandardBankAccount_Over10000_GetsDoubleInterest()
        {
            var bankAccount = new StandardBankAccount
            {
                Balance      = 15000,
                InterestRate = 0.015M
            };
            var interest = CalculateInterest(bankAccount);

            interest.Should().Be(450M);
        }
コード例 #2
0
        public void StandardBankAccount_Under10000_GetsNormalInterest()
        {
            var bankAccount = new StandardBankAccount
            {
                Balance      = 5000,
                InterestRate = 0.015M
            };
            var interest = CalculateInterest(bankAccount);

            interest.Should().Be(75M);
        }
コード例 #3
0
        private static decimal CalculateInterest(StandardBankAccount ba)
        {
            switch (ba)
            {
            case DodgyBankAccount dba:
                return((dba.Balance * dba.InterestRate) + dba.BrownPaperBag);

            case SuperDuperBankAccount sdba:
                return(sdba.Balance * (sdba.BonusInterestRate + sdba.InterestRate));

            case StandardBankAccount sba when sba.Balance <= 10000:
                return(sba.Balance * sba.InterestRate);

            case StandardBankAccount sba:
                return(sba.Balance * (sba.InterestRate * 2));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }