public void Should_have_error_when_HourWorked_is_null_or_Negative() { validator = new EmployeeValidator(); Employee EmployeeObjTest = BuilderEmployee.Create().WorkedFor(-1).Build(); validator.ShouldHaveValidationErrorFor(e => e.HoursWorked, EmployeeObjTest); }
/*The gross amount is the result after multiplying HoursWorked and HourRate*/ public void Should_calculate_the_gross_amount_if_employee_has_hourworked_and_hourRate() { var HourWorked = 60; var HourRate = 10; var ItalyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromItaly calculate = new CalculateSalaryFromItaly(ItalyEmployee); var GrossAmountTemplate = HourRate * HourWorked; Assert.Equal(calculate.GrossAmount, GrossAmountTemplate); }
/*the net amount value */ public void Should_calculate_the_net_amount() { var HourWorked = 60; var HourRate = 10; var ItalyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromItaly calculate = new CalculateSalaryFromItaly(ItalyEmployee); calculate.CalculateNetAmount(); var NetAmountTemplate = calculate.GrossAmount - calculate.TaxRateAmount - calculate.SocialTaxAmount - calculate.PensionAmount; Assert.Equal(calculate.NetAmount, NetAmountTemplate); }
/*This is charged at 9% for the first €500 and increases by .1% over every €100 thereafter.*/ public void Should_calculate_the_social_contribution_tax_of_9_percent_if_the_grossamount_is_less_than_500_euro() { var HourWorked = 50; var HourRate = 10; var ItalyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromItaly calculate = new CalculateSalaryFromItaly(ItalyEmployee); calculate.CalculateSocialContribution(); var SocialTaxAmountTemplate = HourRate * HourWorked * .09; Assert.Equal(calculate.SocialTaxAmount, SocialTaxAmountTemplate); }
/*income tax at a rate of 25% for the first €600 and 40% thereafter*/ public void Should_calculate_the_tax_rate_of_25_percenthan() { var HourWorked = 60; var HourRate = 10; var ItalyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromItaly calculate = new CalculateSalaryFromItaly(ItalyEmployee); calculate.CalculateTaxRate(); var TaxeRateAmountTemplate = HourRate * HourWorked * .25; Assert.Equal(calculate.TaxRateAmount, TaxeRateAmountTemplate); }
/*a compulsory pension contribution of 2% is applied*/ public void Should_calculate_the_pension_tax_of_2_percent() { var HourWorked = 60; var HourRate = 10; var GermanyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromGermany calculate = new CalculateSalaryFromGermany(GermanyEmployee); calculate.CalculatePension(); var PensionAmountTemplate = HourRate * HourWorked * .02; Assert.Equal(calculate.PensionAmount, PensionAmountTemplate); }
/*income tax at a rate of 25% is applied on the first €400 and 32% thereafter*/ public void Should_calculate_the_tax_rate_of_32_percent_if_the_grossamount_is_greater_than_400_euro() { var HourWorked = 41; var HourRate = 10; var GermanyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromGermany calculate = new CalculateSalaryFromGermany(GermanyEmployee); calculate.CalculateTaxRate(); var TaxeRateAmountTemplate = HourRate * HourWorked * .32; Assert.Equal(calculate.TaxRateAmount, TaxeRateAmountTemplate); }
/*income tax at a rate of 25% for the first €600 and 40% thereafter*/ public void Should_calculate_the_tax_rate_of_40_percent_if_the_grossamount_is_greater_than_600_euro() { var HourWorked = 61; var HourRate = 10; var IrelandEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromIreland calculate = new CalculateSalaryFromIreland(IrelandEmployee); calculate.CalculateTaxRate(); var TaxeRateAmountTemplate = HourRate * HourWorked * .40; Assert.Equal(calculate.TaxRateAmount, TaxeRateAmountTemplate); }
public void Should_have_create_an_employee() { var EmployeeTemplate = new { HoursWorked = 10, HourRate = (double)40, Location = (Countries)1 }; var EmployeeObject = BuilderEmployee.Create().WorkedFor(_HoursWorked).EarnsForHour(_HourRate).LivesIn(_Location).Build(); //I make a simple compare just to check if the EmployeeTemplate are equal to Employee. EmployeeTemplate.ToExpectedObject().ShouldMatch(EmployeeObject); }
/*This is charged at 9% for the first €500 and increases by .1% over every €100 thereafter.*/ public void Should_calculate_the_social_contribution_tax_of_9_plus_x_percent_if_the_grossamount_is_greater_than_500_euro() { var HourWorked = 60; var HourRate = 10; var ItalyEmployee = BuilderEmployee.Create().EarnsForHour(HourRate).WorkedFor(HourWorked).Build(); CalculateSalaryFromItaly calculate = new CalculateSalaryFromItaly(ItalyEmployee); calculate.CalculateSocialContribution(); var GrossAmountTemplate = HourRate * HourWorked; float ExtraTax = (GrossAmountTemplate - 500) / 100; var SocialTaxAmountTemplate = Math.Round(GrossAmountTemplate * (.09 + (ExtraTax / 100))); Assert.Equal(calculate.SocialTaxAmount, SocialTaxAmountTemplate); }
static void Main(string[] args) { //print and read data. /*I don't implement a unit test for this class. * I have priorizited the calc tests*/ ReadData data = new ReadData(); //Using Building Pattern to create an employee Employee employee = BuilderEmployee.Create().EarnsForHour(data._hourRate) .WorkedFor(data._hoursWorked) .LivesIn(data._location).Build(); //validate objects EmployeeValidator employeeValidator = new EmployeeValidator(); ShowInformation information = new ShowInformation(); //verify if it a valid employee try { employeeValidator.ValidateAndThrow(employee); /* * I have used the Strategy patter to implement Open closed principle. * With this pattern I can associate countries and their relative Calculcate class. * * I don't implement a unit test for this class. * I have priorizited the calc tests */ CalculateStrategy calculate = new CalculateStrategy(employee); //this method exec all calcs from an employe var calcInformations = calculate.CalculateNetAmount(); information.Sucess(employee, calcInformations); } catch (ValidationException ex) { information.Error(ex.Message); } }
public void Should_have_error_when_Location_is_invalid() { Employee EmployeeObjTest = BuilderEmployee.Create().LivesIn(4).Build(); validator.ShouldHaveValidationErrorFor(e => e.Location, EmployeeObjTest); }
public void Should_have_error_when_HourRate_is_null_or_Invalid() { Employee EmployeeObjTest = BuilderEmployee.Create().EarnsForHour(-1).Build(); validator.ShouldHaveValidationErrorFor(e => e.HourRate, EmployeeObjTest); }