예제 #1
0
        public void PhysicalMoneyVAL_When_Change_Money(
            decimal changeValue, Currency changeCurrency, string expected)
        {
            const decimal  value    = 1000M;
            const Currency currency = Currency.PLN;

            //arrange
            string           result           = "OK";
            PhysicalMoneyVAL physicalMoneyVAL = null;

            try
            {
                physicalMoneyVAL = new PhysicalMoneyVAL(
                    value: value, currency: currency);
            }
            catch (PhysicalMoneyVAL_Exception pmv_e)
            {
                result = pmv_e.What();
            }

            //act
            try
            {
                physicalMoneyVAL.ChangePhysicalMoney(
                    new PhysicalMoneyVAL(
                        value: changeValue, currency: changeCurrency));
            }
            catch (PhysicalMoneyVAL_Exception pmv_e)
            {
                result = pmv_e.What();
            }

            if (result.Equals("OK"))
            {
                //Check set value
                if (physicalMoneyVAL._Value != changeValue)
                {
                    result = "Not set value";
                }

                //Check set currency
                if (physicalMoneyVAL._Currency != changeCurrency)
                {
                    result = "Not set currency";
                }
            }

            //assert
            Assert.AreEqual(expected: expected, actual: result);
        }
        public void MockPhysicalMoneyRepository_When_Get_In_Currency(
            decimal currencyRate, Currency currency, string expected)
        {
            string           result = "OK";
            PhysicalMoneyVAL physicalMoneyInCurrency = null;

            //arrange
            MockPhysicalMoneyRepository mockPhysicalMoneyRepository =
                new MockPhysicalMoneyRepository(
                    cashDispenserLibraryTestSettings._SystemSettings);

            //act
            //Try get in currency form file
            try
            {
                physicalMoneyInCurrency =
                    mockPhysicalMoneyRepository.GetInCurrency(
                        currencyRate, currency);
            }
            catch (MockPhysicalMoneyRepository_Exception mpmr_e)
            {
                result = mpmr_e.What();
            }
            catch (Exception ex)
            {
                result = "!!! Issue with open file !!!";
            }

            //Check currency
            if (result.Equals("OK"))
            {
                if (physicalMoneyInCurrency._Currency != currency)
                {
                    result = $"Bad currency for {currency.ToString()}";
                }
            }

            if (result.Equals("OK"))
            {
                //Check value
                if ((physicalMoneyInCurrency._Value)
                    != (PhysicalMoney_txt / currencyRate))
                {
                    result = $"Bad value for {currency.ToString()}";
                }
            }

            //assert
            Assert.AreEqual(expected: expected, actual: result);
        }
예제 #3
0
        public void PhysicalMoneyVAL_When_Init(
            decimal value, Currency currency, string expected)
        {
            //arrange
            string result = "OK";

            PhysicalMoneyVAL physicalMoneyVAL = null;

            try
            {
                physicalMoneyVAL = new PhysicalMoneyVAL(
                    value: value, currency: currency);
            }
            catch (PhysicalMoneyVAL_Exception pmv_e)
            {
                result = pmv_e.What();
            }

            //act
            if (result.Equals("OK"))
            {
                //Check set value
                if (physicalMoneyVAL._Value != value)
                {
                    result = "Not set value";
                }

                //Check set currency
                if (physicalMoneyVAL._Currency != currency)
                {
                    result = "Not set currency";
                }
            }

            //assert
            Assert.AreEqual(expected: expected, actual: result);
        }
예제 #4
0
        public void BasicUser_When_Add_Money(
            decimal addCurrencyRate, decimal addValue,
            Currency addCurrency, string expected)
        {
            string result = "OK";

            //arrange
            BasicUser basicUser = null;

            //Init database
            initData();

            //Init basic users database
            using (StreamWriter sw = new StreamWriter(
                       "cashDispenserDatabase/BasicUsers.txt", false))
            {
                basicUser = new BasicUser(
                    id: 0, pin: new PinVAL(value: "1111"),
                    name: new NameVAL(value: "Imię"),
                    surname: new SurnameVAL(value: "Nazwisko"),
                    bankAccount: new BankAccount(
                        state: new MoneyVAL(
                            value: PhysicalMoney_txt,
                            currency: Currency.PLN)));
                sw.WriteLine($"0;1111;Imię;Nazwisko;{PhysicalMoney_txt.ToString(new CultureInfo("en-US"))};0");
            }

            //Get respectively basic user's from database
            try
            {
                MockBasicUsersRepository mockBasicUsersRepository =
                    new MockBasicUsersRepository(
                        cashDispenserLibraryTestSettings._SystemSettings);

                basicUser = mockBasicUsersRepository.Get(
                    basicUserId: 0);
            }
            catch (MockBasicUsersRepository_Exception mbur_e)
            {
                result = mbur_e.What();
            }

            //act
            if (result.Equals("OK"))
            {
                //Add money
                try
                {
                    basicUser._BankAccount.AddMoney(currencyRate: addCurrencyRate,
                                                    money: new MoneyVAL(value: addValue,
                                                                        currency: addCurrency), basicUser);
                }
                catch (MoneyVAL_Exception m_e)
                {
                    result = m_e.What();
                }
                catch (BankAccount_Exception ba_e)
                {
                    result = ba_e.What();
                }
                catch (Exception ex)
                {
                    result = "!!! Issue with open file !!!";
                }

                if (result.Equals("OK"))
                {
                    //---Check physical money repository state---

                    //Connect with database
                    MockPhysicalMoneyRepository mockPhysicalMoneyRepository =
                        new MockPhysicalMoneyRepository(
                            cashDispenserLibraryTestSettings._SystemSettings);

                    //Get physical money state
                    PhysicalMoneyVAL physicalMoneyState = null;

                    try
                    {
                        physicalMoneyState =
                            mockPhysicalMoneyRepository.GetInCurrency(
                                currencyRate: 1.0M, currency: Currency.PLN);
                    }
                    catch (MockPhysicalMoneyRepository_Exception mpmr_e)
                    {
                        result = mpmr_e.What();
                    }
                    catch (Exception ex)
                    {
                        result = "!!! Issue with open file !!!";
                    }

                    if (result.Equals("OK"))
                    {
                        //Check database value
                        if ((physicalMoneyState._Value - (addValue * addCurrencyRate))
                            != PhysicalMoney_txt)
                        {
                            result = "Bad database value";
                        }

                        if (physicalMoneyState._Currency != Currency.PLN)
                        {
                            result = "Bad database currency";
                        }
                    }
                }
            }

            //assert
            Assert.AreEqual(expected: expected, actual: result);
        }
예제 #5
0
        public void BankAccount_When_Add_Money(
            string[] basicUsersData, decimal addCurrencyRate,
            decimal addValue, Currency addCurrency,
            int basicUserId, string expected)
        {
            string result = "OK";

            //arrange
            BankAccount bankAccount = null;
            BasicUser   basicUser   = null;

            decimal beginBasicUserBankAccountState = -1;

            //Init database
            initData();

            //Init basic users database
            using (StreamWriter sw = new StreamWriter(
                       "cashDispenserDatabase/BasicUsers.txt", false))
            {
                foreach (var basicUserData in basicUsersData)
                {
                    sw.WriteLine(basicUserData);
                }
            }

            //Get respectively basic user's from database
            try
            {
                MockBasicUsersRepository mockBasicUsersRepository =
                    new MockBasicUsersRepository(
                        cashDispenserLibraryTestSettings._SystemSettings);

                basicUser = mockBasicUsersRepository.Get(
                    basicUserId: basicUserId);
            }
            catch (MockBasicUsersRepository_Exception mbur_e)
            {
                result = mbur_e.What();
            }

            //Get basic user's begin account state
            if (result.Equals("OK"))
            {
                beginBasicUserBankAccountState =
                    basicUser._BankAccount.state._Value;
            }

            if (result.Equals("OK"))
            {
                //Create bank account base on respectively basic user
                try
                {
                    bankAccount = new BankAccount(state: new MoneyVAL(
                                                      value: basicUser._BankAccount.state._Value,
                                                      currency: Currency.PLN));
                }
                catch (MoneyVAL_Exception mv_e)
                {
                    result = mv_e.What();
                }
                catch (BankAccount_Exception ba_e)
                {
                    ba_e.What();
                }

                //act
                if (result.Equals("OK"))
                {
                    //Add money
                    try
                    {
                        bankAccount.AddMoney(currencyRate: addCurrencyRate,
                                             money: new MoneyVAL(value: addValue,
                                                                 currency: addCurrency), basicUser);
                    }
                    catch (MoneyVAL_Exception m_e)
                    {
                        result = m_e.What();
                    }
                    catch (BankAccount_Exception ba_e)
                    {
                        result = ba_e.What();
                    }
                    catch (Exception ex)
                    {
                        result = "!!! Issue with open file !!!";
                    }

                    if (result.Equals("OK"))
                    {
                        //---Check physical money repository state---

                        //Connect with database
                        MockPhysicalMoneyRepository mockPhysicalMoneyRepository =
                            new MockPhysicalMoneyRepository(
                                cashDispenserLibraryTestSettings._SystemSettings);

                        //Get physical money state
                        PhysicalMoneyVAL physicalMoneyState = null;

                        try
                        {
                            physicalMoneyState =
                                mockPhysicalMoneyRepository.GetInCurrency(
                                    currencyRate: 1.0M, currency: Currency.PLN);
                        }
                        catch (MockPhysicalMoneyRepository_Exception mpmr_e)
                        {
                            result = mpmr_e.What();
                        }
                        catch (Exception ex)
                        {
                            result = "!!! Issue with open file !!!";
                        }

                        if (result.Equals("OK"))
                        {
                            //Check database value
                            if ((physicalMoneyState._Value - (addValue * addCurrencyRate))
                                != PhysicalMoney_txt)
                            {
                                result = "Bad database value";
                            }

                            //Check database currency
                            if (physicalMoneyState._Currency != Currency.PLN)
                            {
                                result = "Bad database currency";
                            }

                            //--- Check basic user's bank account state in
                            //repository state ---

                            //Connect with database
                            try
                            {
                                MockBasicUsersRepository mockBasicUsersRepository =
                                    new MockBasicUsersRepository(
                                        cashDispenserLibraryTestSettings._SystemSettings);

                                basicUser = mockBasicUsersRepository.Get(
                                    basicUserId: basicUserId);
                            }
                            catch (MockBasicUsersRepository_Exception mbur_e)
                            {
                                result = mbur_e.What();
                            }

                            //Check basic user money's state
                            if (result.Equals("OK"))
                            {
                                if (Math.Abs((basicUser._BankAccount.state._Value -
                                              addValue * addCurrencyRate) -
                                             beginBasicUserBankAccountState) > 0.002M)
                                {
                                    result = "Bad basic user money database result value";
                                }

                                if (basicUser._BankAccount.state._Currency != Currency.PLN)
                                {
                                    result = "Bad basic user money database result currency";
                                }
                            }
                        }
                    }
                }

                //assert
                Assert.AreEqual(expected: expected, actual: result);
            }
        }
예제 #6
0
        public MoneyVAL TakeOutMoney(
            decimal currencyRate, MoneyVAL money, BasicUser user)
        {
            //Validate currency rate
            if (currencyRate <= 0.0M)
            {
                throw new BankAccount_Exception(
                          BankAccount_ExceptionType.BadCurrencyRate);
            }

            //Core currency case
            if (money._Currency == Currency.PLN)
            {
                //Take out money from account
                if (money._Value <= state._Value)
                {
                    //Arrange bank account database connection
                    MockBasicUsersRepository mockBasicUsersRepository =
                        new MockBasicUsersRepository(
                            platformType: SystemSettings._PlatformType);


                    //Update Basic user account state
                    var basicUser = mockBasicUsersRepository.Get(
                        basicUserId: user._Id);

                    basicUser._BankAccount.state.ChangeMoney(
                        moneyVAL: new MoneyVAL(
                            value: (basicUser._BankAccount.state._Value
                                    - money._Value),
                            currency: Currency.PLN));

                    //Save changes
                    mockBasicUsersRepository.Update(basicUser);

                    //Arrange physical money database connection
                    MockPhysicalMoneyRepository mockPhysicalMoneyRepository =
                        new MockPhysicalMoneyRepository(
                            SystemSettings._PlatformType);

                    //Update bank account state
                    state.ChangeMoney(new MoneyVAL(
                                          value: (state._Value - money._Value), currency: Currency.PLN));

                    //Update physical money state
                    PhysicalMoneyVAL mockPhysicalMoney =
                        mockPhysicalMoneyRepository.GetInCurrency(
                            currencyRate: currencyRate, currency: Currency.PLN);

                    mockPhysicalMoneyRepository.UpdateInCurrency(
                        currencyRate: currencyRate, new PhysicalMoneyVAL(
                            value: (mockPhysicalMoney._Value - money._Value),
                            currency: Currency.PLN));

                    //Take out money
                    return(money);
                }
                //To little money to take out money case
                else
                {
                    throw new BankAccount_Exception(
                              BankAccount_ExceptionType.TooLittleMoney);
                }
            }
            //Others currency case
            else
            {
                //Take out money from account
                if (money._Value <= (state._Value / currencyRate))
                {
                    //Arrange bank account database connection
                    MockBasicUsersRepository mockBasicUsersRepository =
                        new MockBasicUsersRepository(
                            platformType: SystemSettings._PlatformType);


                    //Update Basic user account state
                    var basicUser = mockBasicUsersRepository.Get(
                        basicUserId: user._Id);

                    basicUser._BankAccount.state.ChangeMoney(
                        moneyVAL: new MoneyVAL(
                            value: (basicUser._BankAccount.state._Value
                                    - (money._Value * currencyRate)),
                            currency: Currency.PLN));

                    //Save changes
                    mockBasicUsersRepository.Update(basicUser);

                    //Arrange physical money database connection
                    MockPhysicalMoneyRepository mockPhysicalMoneyRepository =
                        new MockPhysicalMoneyRepository(SystemSettings._PlatformType);

                    //Update bank account state
                    state.ChangeMoney(new MoneyVAL(
                                          value: (state._Value - (money._Value * currencyRate)),
                                          currency: Currency.PLN));

                    //Update physical money state
                    PhysicalMoneyVAL mockPhysicalMoney =
                        mockPhysicalMoneyRepository.GetInCurrency(
                            currencyRate: currencyRate, currency: money._Currency);

                    mockPhysicalMoneyRepository.UpdateInCurrency(
                        currencyRate: currencyRate, new PhysicalMoneyVAL(
                            value: (mockPhysicalMoney._Value - money._Value),
                            currency: money._Currency));

                    //Take out money
                    return(money);
                }
                //To little money to take out money case
                else
                {
                    throw new BankAccount_Exception(
                              BankAccount_ExceptionType.TooLittleMoney);
                }
            }
        }
        public void MockPhysicalMoneyRepository_When_Update_In_Currency(
            decimal currencyRate, decimal value,
            Currency currency, string expected)
        {
            string result = "OK";

            //arrange
            MockPhysicalMoneyRepository mockPhysicalMoneyRepository =
                new MockPhysicalMoneyRepository(
                    cashDispenserLibraryTestSettings._SystemSettings);

            PhysicalMoneyVAL getPhysicalMoneyInCurrency = null;

            //act
            //Update physical money state
            try
            {
                mockPhysicalMoneyRepository.UpdateInCurrency(
                    currencyRate: currencyRate, new PhysicalMoneyVAL(
                        value: value, currency: currency));
            }
            catch (PhysicalMoneyVAL_Exception pmv_e)
            {
                result = pmv_e.What();
            }
            catch (MockPhysicalMoneyRepository_Exception mpmr_e)
            {
                result = mpmr_e.What();
            }
            catch (Exception ex)
            {
                result = "!!! Issue with open file !!!";
            }

            //Get update's physical money
            try
            {
                getPhysicalMoneyInCurrency = mockPhysicalMoneyRepository.GetInCurrency(
                    currencyRate: currencyRate, currency: currency);
            }
            catch (MockPhysicalMoneyRepository_Exception mpmr_e)
            {
                result = mpmr_e.What();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            //Check value and currency
            if (result.Equals("OK"))
            {
                if (getPhysicalMoneyInCurrency._Value != value)
                {
                    result = "!!! Bad value !!!";
                }

                if (getPhysicalMoneyInCurrency._Currency != currency)
                {
                    result = "!!! Bad currency !!!";
                }
            }

            //assert
            Assert.AreEqual(expected: expected, actual: result);
        }