public Decimal Calculate(int year, decimal annualIncome, EmployeeTaxFilingStatus filingStatus = EmployeeTaxFilingStatus.Single) { if (year < TaxTables.Minimum_Year) { throw new ArgumentOutOfRangeException("Unable to process tax years before " + TaxTables.Minimum_Year); } if (annualIncome < 0) { throw new ArgumentOutOfRangeException("AnnualIncome cannot be negative"); } // Get the appropriate table by year // Then figure out the correct row based on filing status and income TaxTableEntry entry = TaxTables .Values .Where(t => t.Year == year) .SelectMany(t => t.Brackets) .Where(e => e.TaxFilingStatus == filingStatus) .Where(e => e.Minimum <= annualIncome) .Where(e => annualIncome < e.Maximum) .SingleOrDefault(); if (entry == null) { throw new ArgumentOutOfRangeException("Unable to find tax table that matches parameters"); } // Formula is Base amount + the difference between the income and the minimum for the bracket * the percentage in that bracket return((entry.Base + ((annualIncome - entry.Minimum) * (entry.Percentage / 100))).Round()); }
public Decimal Verify_Withholding(Decimal annualIncome, EmployeeTaxFilingStatus status) { return(_calculator.Calculate(YEAR, annualIncome, status)); }
public void Should_Return_No_Withholding_For_Married( [Values(EmployeeTaxFilingStatus.MarriedFilingJointly, EmployeeTaxFilingStatus.WidowerWithDependentChild)] EmployeeTaxFilingStatus status, [Random(0, 8450, 5)] Decimal annualIncome) { Assert.That(_calculator.Calculate(YEAR, annualIncome, status), Is.EqualTo(0)); }
public void Should_Return_No_Withholding_For_Single( [Values(EmployeeTaxFilingStatus.Single, EmployeeTaxFilingStatus.MarriedFilingSeparately, EmployeeTaxFilingStatus.HeadOfHousehold)] EmployeeTaxFilingStatus status, [Random(0, 2250, 5)] Decimal annualIncome) { Assert.That(_calculator.Calculate(YEAR, annualIncome, status), Is.EqualTo(0)); }