public WPFViewModel(RealFileProvider realFileProvider) { History = new ObservableCollection <IncomeTaxCalFinder>(); INotifyPropertyChanged notify; this.fileProvider = new RealFileProvider(); IncomeCalculator = new IncomeTaxCalFinder(); IncomeCalculator.Income = 75000; States = IncomeCalculator.taxRates; CalculateCommand = new DelegateCommand(() => { if (IncomeCalculator.Income <= 0) { MessageBox.Show("Income must be greater the zero."); return; } IncomeCalculator.State = SelectedState; if (IncomeCalculator.State == null) { MessageBox.Show("A state must be selected"); return; } IncomeCalculator.taxableIncome(); History.Add(IncomeCalculator); ExportToExcel.RaiseCanExecuteChanged(); IncomeCalculator = IncomeCalculator.Clone() as IncomeTaxCalFinder; RaisePropertyChanged(nameof(IncomeCalculator)); }); }
public void TestTaxableIncome() { var incomeTax = new IncomeTaxCalFinder { State = "AL", Income = 45000 }; decimal expected = 43200; decimal actual = incomeTax.taxableIncome(); Assert.AreEqual(expected, actual); // If income is less then zero then this method will return zero try { var badIncomeTax = new IncomeTaxCalFinder { State = "AL", Income = -45000 }; Assert.Fail("Negative income should throw an exception."); } catch (ArgumentOutOfRangeException ar) { Assert.Pass("Negative income throws an exception."); } }
private void getNewIncome_Click(object sender, EventArgs e) { IncomeTaxCalFinder calc = new IncomeTaxCalFinder(); calc.Income = decimal.Parse(txtIncomeBox.Text); if (calc.Income <= 0) { MessageBox.Show("Income must be greater then zero."); return; } calc.State = combState.Text; if (combState.SelectedIndex == -1) { MessageBox.Show("Please select a state"); return; } txtNewIncome.Text = calc.taxableIncome().ToString("c"); CalcHistory.Count(); CalcHistory.Add(calc); }