private void ChangeCashDispenserStateButton_Click(object sender, EventArgs e) { // Connect with database try { if (this.ChangeCashDispenserValueValueTextBox.TextLength == 0) { ErrorLabel.Show(); ErrorLabel.Text = "Niedozwolona Wartość Kwoty"; throw new Exception(); } MockPhysicalMoneyRepository mockPhysicalMoneyRepository = new MockPhysicalMoneyRepository(SystemSettings._PlatformType); // Update cash dispenser state mockPhysicalMoneyRepository.UpdateInCurrency( currencyRate: CashWithdrawalProperties.exchangeRates.PLN_exchangeRate, physicalMoneyVAL: new PhysicalMoneyVAL( value: decimal.Parse(this.ChangeCashDispenserValueValueTextBox.Text, CultureInfo.InvariantCulture), currency: Currency.PLN)); // Redirect to administrator change cash dispenser state result panel AdministratorChangeCashDispenserStateResultPanel administratorChangeCashDispenserStateResultPanel = new AdministratorChangeCashDispenserStateResultPanel(); administratorChangeCashDispenserStateResultPanel.ShowDialog(); // Update local cash dispenser state this.cashDispenserStateInPln = mockPhysicalMoneyRepository.GetInCurrency( currencyRate: CashWithdrawalProperties .exchangeRates.PLN_exchangeRate, currency: Currency.PLN)._Value; // Show cash dispenser state after change this.CashDispenserStateValueLabel.Text = (String.Format("{0:0.00}", this.cashDispenserStateInPln)); } catch (MockPhysicalMoneyRepository_Exception mpmr_e) { this.ErrorLabel.Text = mpmr_e.What(); this.ErrorLabel.Show(); } catch (PhysicalMoneyVAL_Exception pm_e) { this.ErrorLabel.Text = pm_e.What(); this.ErrorLabel.Show(); } catch (Exception ex) { } }
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); }
private void AdministratorCashDispenserStatePanel_VisibleChanged(object sender, EventArgs e) { // Set cash dispenser state information try { // Connect with database MockPhysicalMoneyRepository mockPhysicalMoneyRepository = new MockPhysicalMoneyRepository(SystemSettings._PlatformType); // Get physical money in all currency this.cashDispenserStateInPlnCurrency = mockPhysicalMoneyRepository.GetInCurrency( currencyRate: CashWithdrawalProperties.exchangeRates.PLN_exchangeRate, currency: Currency.PLN)._Value; // Show physical money in default currency this.CashDispenserStateValueLabel.Text = (String.Format("{0:0.00}", cashDispenserStateInPlnCurrency)); } catch (MockPhysicalMoneyRepository_Exception mpmr_e) { } }
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); }
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); } }
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_Get_All_Currency( decimal PLN_currencyRate, decimal USD_currencyRate, decimal EUR_currencyRate, decimal GBP_currencyRate, string expected) { string result = "OK"; IEnumerable <PhysicalMoneyVAL> physicalMoneyInAllCurrency = null; //arrange MockPhysicalMoneyRepository mockPhysicalMoneyRepository = new MockPhysicalMoneyRepository( cashDispenserLibraryTestSettings._SystemSettings); //act try { physicalMoneyInAllCurrency = mockPhysicalMoneyRepository.GetAllCurrency( new Dictionary <Currency, decimal> { { Currency.PLN, PLN_currencyRate }, { Currency.USD, USD_currencyRate }, { Currency.EUR, EUR_currencyRate }, { Currency.GBP, GBP_currencyRate }, }); } catch (MockPhysicalMoneyRepository_Exception mpmr_e) { result = mpmr_e.What(); } catch (Exception ex) { result = "!!! Issue with open file !!!"; } if (result.Equals("OK")) { //Check values correctness foreach (var physicalMoneyInCurrency in physicalMoneyInAllCurrency) { switch (physicalMoneyInCurrency._Currency) { case Currency.PLN: { if (physicalMoneyInCurrency._Value != (PhysicalMoney_txt / PLN_currencyRate)) { result = $"Bad value for {physicalMoneyInCurrency._Currency.ToString()}"; } } break; case Currency.USD: { if (physicalMoneyInCurrency._Value != (PhysicalMoney_txt / USD_currencyRate)) { result = $"Bad value for {physicalMoneyInCurrency._Currency.ToString()}"; } } break; case Currency.EUR: { if (physicalMoneyInCurrency._Value != (PhysicalMoney_txt / EUR_currencyRate)) { result = $"Bad value for {physicalMoneyInCurrency._Currency.ToString()}"; } } break; case Currency.GBP: { if (physicalMoneyInCurrency._Value != (PhysicalMoney_txt / GBP_currencyRate)) { result = $"Bad value for {physicalMoneyInCurrency._Currency.ToString()}"; } } break; default: throw new ArgumentOutOfRangeException(); } } } //assert Assert.AreEqual(expected: expected, actual: result); }
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); }