public uint IncomeTax(uint annualIncome) { TaxBand band = TaxBands.GetTaxBand(annualIncome); double value = band.VariableTax * (annualIncome - band.TaxableIncomeLB - 1) + band.FlatTax; return((uint)Math.Round((double)value / 12, 0, MidpointRounding.AwayFromZero)); }
public void GetTax_WhenBothAmountAndLowerBoundAreZero_ReturnZero() { var taxBand = TaxBand.Create(20, "band1"); var tax = taxBand.GetTax(0, 0); tax.Should().Be(0); }
public void GetTax_WhenUpperBoundIsNull_ReturnsProductOfRateAndDifferenceOfAmountAndLowerBound() { var taxBand = TaxBand.Create(20, "band1"); var tax = taxBand.GetTax(2000m, 10000m); tax.Should().Be((10000m - 2000) * (20 / 100m)); }
public void GetTax_WhenLowerBoundLargerThanAmount_ReturnZero(decimal lowerBound, decimal amount) { var taxBand = TaxBand.Create(20, "band1", 10000); var tax = taxBand.GetTax(lowerBound, amount); tax.Should().Be(0); }
public void GetTax_WhenAmountLargerThanUpperBound_ReturnsProductOfRateAndDifferenceOfUpperBoundAndLowerBound() { var taxBand = TaxBand.Create(20, "band1", 10000); var tax = taxBand.GetTax(2000, 12000); tax.Should().Be((10000m - 2000) * (20 / 100m)); }
public void GetTax_WhenAmountLessThanOrEqualToUpperBound_ReturnsProductOfRateAndDifferenceOfAmountAndLowerBound(decimal amount) { var taxBand = TaxBand.Create(20, "band1", 10000); var tax = taxBand.GetTax(2000, amount); tax.Should().Be((amount - 2000) * (20 / 100m)); }
public double TaxFor(double grossSalary) { var lowerTaxBand = new TaxBand(5000.0, 0.1, null); var middleTaxBand = new TaxBand(20000.0, 0.2, lowerTaxBand); var upperTaxBand = new TaxBand(40000.0, 0.4, middleTaxBand); return(upperTaxBand.TaxFor(grossSalary)); }
public void CompareTo_Test(decimal?upperBound1, decimal?upperBound2, int expectedResult) { var taxBand1 = TaxBand.Create(20, "band1", upperBound1); var taxBand2 = TaxBand.Create(20, "band2", upperBound2); var result = taxBand1.CompareTo(taxBand2); result.Should().Be(expectedResult); }
private void Init(bool isPostBack) { InitMessage(); _IEditTaxBandView.Title = "ÐÞ¸ÄË°½×"; if (!isPostBack) { TaxBand taxBand = _ITax.GetTaxBandByTaxBandID(_IEditTaxBandView.TaxBandID); _IEditTaxBandView.BandMin = taxBand.BandMin.ToString(); _IEditTaxBandView.TaxRate = (taxBand.TaxRate * 100).ToString(); } }
public double TaxFor(double grossSalary) { var upperTaxBand = new TaxBand(40000.0, 0.4); var upperTaxBracketTax = upperTaxBand.TaxInBand(grossSalary); var remainingGrossForMiddleAndLowerBrackets = upperTaxBand.GrossToTaxInBandsBelowCurrent(grossSalary); var middleTaxBand = new TaxBand(20000.0, 0.2); var middleTaxBracketTax = middleTaxBand.TaxInBand(remainingGrossForMiddleAndLowerBrackets); var remainingGrossForLowerBracket = middleTaxBand.GrossToTaxInBandsBelowCurrent(remainingGrossForMiddleAndLowerBrackets); var lowerTaxBand = new TaxBand(5000.0, 0.1); var lowerTaxBracketTax = lowerTaxBand.TaxInBand(remainingGrossForLowerBracket); return(lowerTaxBracketTax + middleTaxBracketTax + upperTaxBracketTax); }
public List <TaxBand> GetAllTaxBand() { List <TaxBand> taxBandList = new List <TaxBand>(); SqlCommand cmd = new SqlCommand(); using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetAllTaxBand", cmd)) { while (sdr.Read()) { TaxBand taxBand = new TaxBand(Convert.ToInt32(sdr[_DbPKID]), Convert.ToDecimal(sdr[_DbBandMin]), Convert.ToDecimal(sdr[_DbTaxRate])); taxBandList.Add(taxBand); } } return(taxBandList); }
public TaxBand GetTaxBandByTaxBandID(int taxBandID) { TaxBand taxBand = null; SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_PKID, SqlDbType.Int).Value = taxBandID; using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetTaxBandByTaxBandID", cmd)) { while (sdr.Read()) { taxBand = new TaxBand(Convert.ToInt32(sdr[_DbPKID]), Convert.ToDecimal(sdr[_DbBandMin]), Convert.ToDecimal(sdr[_DbTaxRate])); } } return(taxBand); }
public void IntegrationTest_WithMockProvider() { (var taxBandProviderMock, _, _) = GetMocks(); var band1 = TaxBand.Create(0, "band1", 12_500m); var band2 = TaxBand.Create(20, "band2", 50_000m); var band3 = TaxBand.Create(40, "band3", 150_000m); var band4 = TaxBand.Create(45, "band4"); var taxBands = new List <TaxBand>() { band1, band2, band3, band4 }; taxBandProviderMock.Setup(x => x.GetAll()).Returns(taxBands); var service = new CalculateTaxService(taxBandProviderMock.Object, new TaxBandHelper()); (var tax, _) = service.GetTax(52_000m); tax.Should().Be(8_300m); }
public TaxBand(double minimumGross, double taxRate, TaxBand lowerTaxBand) { this.minimumGross = minimumGross; this.taxRate = taxRate; this.lowerTaxBand = lowerTaxBand; }
private double CalculateTaxInBand(TaxBand taxBand) { return(MonetaryAmountInBand(taxBand.LowerBand, taxBand.RangeOfBand) * taxBand.Percentage); }
public void GetTax_WhenLowerBoundLessThanZero_ThrowError() { var taxBand = TaxBand.Create(20, "band1"); taxBand.Invoking(x => x.GetTax(-1m, 1m)).Should().Throw <InvalidOperationException>(); }