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 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); }