예제 #1
0
        public double Post(WorkTime workTime)
        {
            PayCalculator payCalculator = new PayCalculator();
            double        pay           = payCalculator.GetEmployeePay(workTime);

            return(pay);
        }
예제 #2
0
        public void GeneratePayslip_creates_valid_payslip()
        {
            // Arrange
            var payCalculator = new PayCalculator();
            var taxTable      = new TaxTable();

            // Act
            var payslipGenerator = new PayslipGenerator(payCalculator, taxTable);
            var payslip          = payslipGenerator.GeneratePayslip(_employee)
                                   .Split(',')
                                   .Select(x => x.Trim())
                                   .ToArray();

            // Name
            Assert.AreEqual(payslip[0], "John Smith");

            // Pay period
            Assert.AreEqual(payslip[1].Trim(), "01 March - 31 March");

            // Gross income
            Assert.AreEqual(payslip[2], "10000");

            // Income tax
            Assert.AreEqual(payslip[3], "2696");

            // Net income
            Assert.AreEqual(payslip[4], "7304");

            // Super
            Assert.AreEqual(payslip[5], "900");
        }
예제 #3
0
        public void WhenInstantiatingCalculatorIsNotNull()
        {
            var testStart  = 5;
            var testEnd    = 8;
            var calculator = new PayCalculator(testStart, testEnd);

            calculator.ShouldNotBeNull();
        }
예제 #4
0
        public void WhenCalculatingAfternoonHoursReturnsAfternoonRateTimesTotal()
        {
            var testStart  = 1;
            var testEnd    = 4;
            var calculator = new PayCalculator(testStart, testEnd);

            var result = calculator.CalculatePay();

            result.ShouldBe(3 * 7);
        }
예제 #5
0
        public void WhenCalculatingNightAndEveningPayReturnsEveningRatePlusNightRate()
        {
            var testStart  = 9;
            var testEnd    = 11;
            var calculator = new PayCalculator(testStart, testEnd);

            var result = calculator.CalculatePay();

            result.ShouldBe(11 + 13);
        }
예제 #6
0
        public void WhenCalculationNightPayReturnsNightRateTimesTotalHours()
        {
            var testStart  = 10;
            var testEnd    = 11;
            var calculator = new PayCalculator(testStart, testEnd);

            var result = calculator.CalculatePay();

            result.ShouldBe(1 * 13);
        }
예제 #7
0
        public void WhenCalculatingEveningPayReturnsEveningRateTimesTotalHours()
        {
            var testStart  = 5;
            var testEnd    = 8;
            var calculator = new PayCalculator(testStart, testEnd);

            var result = calculator.CalculatePay();

            result.ShouldBe(3 * 11);
        }
예제 #8
0
        public void WhenCalculatingFullDayPayReturnsMaxPay()
        {
            var testStart  = 1;
            var testEnd    = 12;
            var calculator = new PayCalculator(testStart, testEnd);

            var result = calculator.CalculatePay();

            result.ShouldBe(109);
        }
예제 #9
0
        public void GetNetPayTest()
        {
            const decimal grossPay       = 1000;
            const decimal taxRate        = .10m;
            const decimal expectedNetPay = 900;

            PayCalculator payCalculator = new PayCalculator();
            decimal       actualNetPay  = payCalculator.CalculateNetPay(grossPay, taxRate);

            Assert.IsTrue(expectedNetPay == actualNetPay, $"Expected net pay {expectedNetPay}. Actual net pay {actualNetPay}");
        }
예제 #10
0
        public void CalculateGrossPayTest()
        {
            const decimal regularPay       = 400;
            const decimal overTimePay      = 100;
            const decimal expectedGrossPay = 500;

            PayCalculator payCalculator  = new PayCalculator();
            decimal       actualGrossPay = payCalculator.CalculateGrossPay(regularPay, overTimePay);

            Assert.IsTrue(actualGrossPay == expectedGrossPay, $"Expected gross pay {expectedGrossPay}. Actual gross pay {actualGrossPay}");
        }
예제 #11
0
        public void CalculateOvertimePayWhenOvertimeIsPresentTest()
        {
            const int     hoursWorkedWithOverTime = 41;
            const int     hourlyRate          = 10;
            const decimal expectedOvertimePay = 15;
            const decimal overtimeFactor      = 1.5m;

            PayCalculator payCalculator     = new PayCalculator();
            decimal       actualOvertimePay = payCalculator.CalculateOvertimePay(hoursWorkedWithOverTime, hourlyRate, overtimeFactor);

            Assert.IsTrue(expectedOvertimePay == actualOvertimePay,
                          $"Expected overtime pay {expectedOvertimePay} to equal actual overtime pay {actualOvertimePay}");
        }
예제 #12
0
        public void CalculateRegularPayWithOvertimeTest()
        {
            const int     hoursWorked        = 41;
            const int     hourlyRate         = 10;
            const decimal expectedRegularPay = 400;

            PayCalculator payCalculator    = new PayCalculator();
            decimal       actualRegularPay = payCalculator.CalculateRegularPay(hoursWorked, hourlyRate);

            Assert.IsTrue(
                expectedRegularPay == actualRegularPay,
                $"Expected regular pay {expectedRegularPay} to equal actual pay {actualRegularPay}");
        }
        public void TestGetEmployeePay()
        {
            var payCalculator = new PayCalculator();
            var workTime      = new WorkTime()
            {
                StartTime = 1,
                EndTime   = 12
            };
            double expected = 136.00;

            double result = payCalculator.GetEmployeePay(workTime);

            Assert.IsTrue(result == expected);
        }
예제 #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Pay Calculator!");
            Console.Write("Please Enter Starting Hour: ");
            var startingHour = Console.ReadLine();

            Console.Write("Please Enter Ending Hour: ");
            var endingHour = Console.ReadLine();

            var calculator = new PayCalculator(int.Parse(startingHour), int.Parse(endingHour));

            var payAmount = calculator.CalculatePay();

            Console.WriteLine($"This babysitter is owed: ${payAmount}.00");
        }
예제 #15
0
        public void GetTaxRateTest()
        {
            const string  marriedUpper            = "M";
            const string  singleUpper             = "S";
            const string  widowedUpper            = "W";
            const string  divorcedUpper           = "D";
            const string  marriedLower            = "m";
            const string  singleLower             = "s";
            const string  widowedLower            = "w";
            const string  divorcedLower           = "d";
            const decimal expectedMarriedTaxRate  = .15m;
            const decimal expectedSingleTaxRate   = .22m;
            const decimal expectedWidowedTaxRate  = .13m;
            const decimal expectedDivorcedTaxRate = .23m;

            PayCalculator payCalculator             = new PayCalculator();
            decimal       actualMarriedTaxRateUpper = payCalculator.CalculateTaxRate(marriedUpper);

            Assert.IsTrue(expectedMarriedTaxRate == actualMarriedTaxRateUpper, $"Expected married tax rate {expectedMarriedTaxRate} when marital status is {marriedUpper}. Actual tax rate {actualMarriedTaxRateUpper}");

            decimal actualMarriedTaxRateLower = payCalculator.CalculateTaxRate(marriedLower);

            Assert.IsTrue(expectedMarriedTaxRate == actualMarriedTaxRateUpper, $"Expected married tax rate {expectedMarriedTaxRate} when marital status is {marriedLower}. Actual tax rate {actualMarriedTaxRateLower}");

            decimal actualSingleTaxRateUpper = payCalculator.CalculateTaxRate(singleUpper);

            Assert.IsTrue(expectedSingleTaxRate == actualSingleTaxRateUpper, $"Expected single tax rate {expectedSingleTaxRate} when marital status is {singleUpper}. Actual tax rate {actualSingleTaxRateUpper}");

            decimal actualSingleTaxRateLower = payCalculator.CalculateTaxRate(singleLower);

            Assert.IsTrue(expectedSingleTaxRate == actualSingleTaxRateUpper, $"Expected single tax rate {expectedSingleTaxRate} when marital status is {singleLower}. Actual tax rate {actualSingleTaxRateLower}");

            decimal actualDivorcedTaxRateUpper = payCalculator.CalculateTaxRate(divorcedUpper);

            Assert.IsTrue(expectedDivorcedTaxRate == actualDivorcedTaxRateUpper, $"Expected divorced tax rate {expectedDivorcedTaxRate} when marital status is {divorcedUpper}. Actual tax rate {actualDivorcedTaxRateUpper}");

            decimal actualDivorcedTaxRateLower = payCalculator.CalculateTaxRate(divorcedLower);

            Assert.IsTrue(expectedDivorcedTaxRate == actualDivorcedTaxRateUpper, $"Expected divorced tax rate {expectedDivorcedTaxRate} when marital status is {divorcedLower}. Actual tax rate {actualDivorcedTaxRateLower}");

            decimal actualWidowedTaxRateUpper = payCalculator.CalculateTaxRate(widowedUpper);

            Assert.IsTrue(expectedWidowedTaxRate == actualWidowedTaxRateUpper, $"Expected widowed tax rate {expectedWidowedTaxRate} when marital status is {widowedUpper}. Actual tax rate {actualWidowedTaxRateUpper}");

            decimal actualWidowedTaxRateLower = payCalculator.CalculateTaxRate(widowedLower);

            Assert.IsTrue(expectedWidowedTaxRate == actualWidowedTaxRateUpper, $"Expected widowed tax rate {expectedWidowedTaxRate} when marital status is {widowedLower}. Actual tax rate {actualWidowedTaxRateLower}");
        }
예제 #16
0
        public void CalculateRegularPayWithoutOverTimeTest()
        {
            const int     hoursWorkedFourty         = 40;
            const int     hoursWorkedLessThanFourty = 30;
            const int     hourlyRate = 10;
            const decimal expectedRegularPayExactly40Hours      = 400;
            const decimal expectedRegularPayLessThanFourtyHours = 300;

            PayCalculator payCalculator = new PayCalculator();

            decimal actualRegularPayExactly40Hours = payCalculator.CalculateRegularPay(hoursWorkedFourty, hourlyRate);

            Assert.IsTrue(expectedRegularPayExactly40Hours == actualRegularPayExactly40Hours, $"Expected regular pay for fourty hours {expectedRegularPayExactly40Hours} does not equal actual pay for fourty hours {actualRegularPayExactly40Hours}");

            decimal actualRegularPayLessThan40Hours = payCalculator.CalculateRegularPay(hoursWorkedLessThanFourty, hourlyRate);

            Assert.IsTrue(expectedRegularPayLessThanFourtyHours == actualRegularPayLessThan40Hours, $"Expected regular pay for less than fourty hours {expectedRegularPayLessThanFourtyHours} does not equal actual pay for less than fourty hours {actualRegularPayLessThan40Hours}");
        }
예제 #17
0
        public void CalculateOvertimePayWhenOvertimeIsNotPresentTest()
        {
            const int     hoursWorkedExactlyRegularPayInterval  = 40;
            const int     hoursWorkedLessThanRegularPayInterval = 39;
            const int     hourlyRate          = 10;
            const decimal expectedOvertimePay = 0;
            const decimal overtimeFactor      = 1.5m;

            PayCalculator payCalculator = new PayCalculator();
            decimal       actualOvertimePayWhenHoursWorkedIsExactlyRegularPayInteveral = payCalculator.CalculateOvertimePay(hoursWorkedExactlyRegularPayInterval, hourlyRate, overtimeFactor);

            Assert.IsTrue(expectedOvertimePay == actualOvertimePayWhenHoursWorkedIsExactlyRegularPayInteveral,
                          $"Expected overtime pay {expectedOvertimePay} when hours worked {hoursWorkedExactlyRegularPayInterval} is equal to the regular pay interval to equal actual overtime pay {actualOvertimePayWhenHoursWorkedIsExactlyRegularPayInteveral}");

            decimal actualOvertimePayWhenHoursWorkedIsLessThanRegularPayInteveral = payCalculator.CalculateOvertimePay(hoursWorkedLessThanRegularPayInterval, hourlyRate, overtimeFactor);

            Assert.IsTrue(expectedOvertimePay == actualOvertimePayWhenHoursWorkedIsLessThanRegularPayInteveral,
                          $"Expected overtime pay {expectedOvertimePay} when hours worked {hoursWorkedLessThanRegularPayInterval} is equal to the regular pay interval to equal actual overtime pay {actualOvertimePayWhenHoursWorkedIsLessThanRegularPayInteveral}");
        }
예제 #18
0
        public IActionResult CreatePayCheck(Guid empId)
        {
            var employeeFromRepo = _appRepository.GetEmployee(empId);

            if (employeeFromRepo == null)
            {
                return(NotFound());
            }

            var payCheckEntity = PayCalculator.GeneratePayCheck(employeeFromRepo);

            _appRepository.AddPayCheck(payCheckEntity);

            if (!_appRepository.Save())
            {
                throw new Exception($"Creation of pay check for employee {empId} failed on save.");
            }

            var payCheckToReturn = Mapper.Map <PayCheckDto>(payCheckEntity);

            return(CreatedAtRoute("GetPayCheck", new { empId = employeeFromRepo.EmpId, txnId = payCheckEntity.TxnId }, payCheckToReturn));
        }
예제 #19
0
 public void SetUp()
 {
     payCalculator = new PayCalculator();
 }
예제 #20
0
 public void Setup()
 {
     _payCalculator = new PayCalculator();
 }