コード例 #1
0
        /// <summary>
        /// Constructor of the bank account class
        /// </summary>
        /// <param name="iban">International Bank Account Number</param>
        /// <param name="ownerInformation">First and Last name</param>
        /// <param name="balance">Balance of the bank account</param>
        /// <param name="bonus">Bonus of the bank account</param>
        /// <param name="type">Type of bank account</param>
        public BankAccount(string iban, string ownerInformation, decimal balance, float bonus, TypeBankAccount type)
        {
            ValidateIBAN(iban);
            ValidateOwner(ownerInformation);
            ValidateBonus(bonus);
            ValidateBalance(balance);

            IBAN             = iban;
            OwnerInformation = ownerInformation;
            Balance          = balance;
            Bonus            = bonus;
            TypeBankAccount  = type;
        }
コード例 #2
0
        public IEnumerable <BankAccount> Load()
        {
            List <BankAccount> listLoadBankAccounts = new List <BankAccount>();

            using (Stream stream = File.Open(this.Path, FileMode.OpenOrCreate))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    while (binaryReader.PeekChar() > -1)
                    {
                        int             id              = binaryReader.ReadInt32();
                        string          holderName      = binaryReader.ReadString();
                        decimal         balance         = binaryReader.ReadDecimal();
                        int             bonusPoints     = binaryReader.ReadInt32();
                        TypeBankAccount typeBankAccount = (TypeBankAccount)binaryReader.ReadInt32();
                        BankAccount     account         = this.BankAccountFactory.GetInstance(id, holderName, balance, bonusPoints, typeBankAccount);

                        listLoadBankAccounts.Add(account);
                    }
                }
            }

            return(listLoadBankAccounts);
        }
コード例 #3
0
        public void BankAccountTest_Withdraw_NotEnoughMoneyException(int id, string name, decimal balance, int bonusPoints, TypeBankAccount type)
        {
            Mock <ICalculatorBonusPoints> mockBonusPointsToWithfraw = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToWithfraw
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsWithdraw);

            Mock <ICalculatorBonusPoints> mockBonusPointsToDeposit = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToDeposit
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsDeposit);

            //Mock<IBankAccountFactory> mockBankAccountFactory = new Mock<IBankAccountFactory>();
            //mockBankAccountFactory
            //    .Setup(m => m.GetInstance(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<TypeBankAccount>()))
            //    .Returns<int, string, decimal, int, TypeBankAccount>((id, name, balance, bonus, type) => CalculateBankAccount(id, name, balance, bonus, type, mockBonusPointsToWithfraw.Object, mockBonusPointsToDeposit.Object));


            IBankAccountFactory factory = new BankAccountFactory()
            {
                ToDeposit  = mockBonusPointsToDeposit.Object,
                ToWithdraw = mockBonusPointsToWithfraw.Object
            };

            BankAccount account = factory.GetInstance(id, name, balance, bonusPoints, type);

            Assert.Throws <NotEnoughMoneyException>(
                () => account.WithdrawMoney(999));
        }
コード例 #4
0
        public void BankAccountTest_Deposit_BaseAccount(int id, string name, decimal balance, int bonusPoints, TypeBankAccount type)
        {
            Mock <ICalculatorBonusPoints> mockBonusPointsToWithfraw = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToWithfraw
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsWithdraw);

            Mock <ICalculatorBonusPoints> mockBonusPointsToDeposit = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToDeposit
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsDeposit);

            //Mock<IBankAccountFactory> mockBankAccountFactory = new Mock<IBankAccountFactory>();
            //mockBankAccountFactory
            //    .Setup(m => m.GetInstance(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<decimal>(), It.IsAny<int>(), It.IsAny<TypeBankAccount>()))
            //    .Returns<int, string, decimal, int, TypeBankAccount>((id, name, balance, bonus, type) => CalculateBankAccount(id, name, balance, bonus, type, mockBonusPointsToWithfraw.Object, mockBonusPointsToDeposit.Object));


            IBankAccountFactory factory = new BankAccountFactory()
            {
                ToDeposit  = mockBonusPointsToDeposit.Object,
                ToWithdraw = mockBonusPointsToWithfraw.Object
            };

            BankAccount account = factory.GetInstance(id, name, balance, bonusPoints, type);

            account.DepositMoney(1000);

            Assert.AreEqual(1000, account.Balance);
            Assert.AreEqual(account.BonusPointsDeposit, account.BonusPoints);
        }
コード例 #5
0
        /// <summary>
        /// Create an instance <see cref="BankAccount"/>.
        /// </summary>
        /// <param name="id">The identifier of bank account.</param>
        /// <param name="name">The name of a holder.</param>
        /// <param name="balance">The balance.</param>
        /// <param name="bonusPoints">Bonus points.</param>
        /// <param name="type">Wich type of <see cref="BankAccount"/> need to create.</param>
        /// <returns>An instance of <see cref="BankAccount"/>.</returns>
        public BankAccount GetInstance(int id, string name, decimal balance, int bonusPoints, TypeBankAccount type)
        {
            switch (type)
            {
            case TypeBankAccount.Base:
                return(new BaseAccount(id, name, balance, bonusPoints));

                break;

            case TypeBankAccount.Golden:
                return(new GoldAccount(id, name, balance, bonusPoints));

                break;

            case TypeBankAccount.Platinum:
                return(new PlatinumAccount(id, name, balance, bonusPoints));

                break;

            default:
                return(new BaseAccount(id, name, balance, bonusPoints));
            }
        }
コード例 #6
0
        public BankAccount GetInstance(int id, string name, decimal balance, int bonusPoints, TypeBankAccount type, ICalculatorBonusPoints toDeposit, ICalculatorBonusPoints toWithdraw)
        {
            switch (type)
            {
            case TypeBankAccount.Base:
                return(new BaseAccount(id, name, balance, bonusPoints, toWithdraw, toDeposit));

            case TypeBankAccount.Golden:
                return(new GoldAccount(id, name, balance, bonusPoints, toWithdraw, toDeposit));

            case TypeBankAccount.Platinum:
                return(new PlatinumAccount(id, name, balance, bonusPoints, toWithdraw, toDeposit));

            default:
                return(new BaseAccount(id, name, balance, bonusPoints, toWithdraw, toDeposit));
            }
        }
コード例 #7
0
        public void BankAccountServiceTest_Add_BankAccount_Succed(int id, string name, decimal balance, int bonusPoints, TypeBankAccount type)
        {
            Mock <ICalculatorBonusPoints> mockBonusPointsToWithfraw = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToWithfraw
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsWithdraw);

            Mock <ICalculatorBonusPoints> mockBonusPointsToDeposit = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToDeposit
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsDeposit);

            Mock <IBankAccountFactory> mockBankAccountFactory = new Mock <IBankAccountFactory>();

            mockBankAccountFactory
            .Setup(m => m.GetInstance(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <int>(), It.IsAny <TypeBankAccount>()))
            .Returns <int, string, decimal, int, TypeBankAccount>((idF, nameF, balanceF, bonus, typeF) => GetInstance(idF, nameF, balanceF, bonus, typeF, mockBonusPointsToWithfraw.Object, mockBonusPointsToDeposit.Object));

            BankAccountMapper          mapper = new BankAccountMapper(mockBankAccountFactory.Object);
            Mock <IBankAccountStorage> mockBankAccountStorage = new Mock <IBankAccountStorage>();

            mockBankAccountStorage
            .Setup(m => m.Load())
            .Returns(() =>
            {
                return(new List <AccountDTO>());
            });
            mockBankAccountStorage
            .Setup(m => m.Save(It.IsAny <IEnumerable <AccountDTO> >()));

            IBankAccountService service = new BankAccountService(mockBankAccountStorage.Object, mapper);

            service.Add(new BaseAccount(1, name, balance, bonusPoints));
            Assert.AreEqual(1, service.Count());
        }