public void TestHourlyUnionMemberServiceCharge()
        {
            int empId = 12;
            var t     = new AddHourlyEmployee(empId, "Bill", "Home", 15.24m);

            t.Execute();

            int memberId = 1337;
            var cmt      = new ChangeMemberTransaction(empId, memberId, 9.42m);

            cmt.Execute();
            DateTime payDate             = new DateTime(2020, 03, 20);
            ServiceChargeTransaction sct = new ServiceChargeTransaction(memberId, payDate, 19.42m);

            sct.Execute();
            TimeCardTransaction tct = new TimeCardTransaction(payDate, 8.0, empId);

            tct.Execute();
            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();
            Paycheck pc = pt.GetPaycheck(empId);

            ValidatePaycheck(pt, empId, payDate, 8 * 15.24m, 9.42m + 19.42m);
        }
        public void TestServiceChargesSpanningMultiplePayPeriods()
        {
            int empId = 1;
            var t     = new AddHourlyEmployee(empId, "Bill", "Home", 15.23m);

            t.Execute();

            int memberId = 1234;
            var cmt      = new ChangeMemberTransaction(empId, memberId, 9.42m);

            cmt.Execute();

            var payDate   = new DateTime(2020, 03, 20);
            var earlyDate = new DateTime(2020, 03, 13);
            var lateDate  = new DateTime(2020, 03, 27);

            var sct = new ServiceChargeTransaction(memberId, payDate, 19.42m);

            sct.Execute();
            var sctEarly = new ServiceChargeTransaction(memberId, earlyDate, 100.00m);

            sctEarly.Execute();
            var sctLate = new ServiceChargeTransaction(memberId, lateDate, 100.00m);

            sctLate.Execute();
            var tct = new TimeCardTransaction(payDate, 8.0, empId);

            tct.Execute();
            var pt = new PaydayTransaction(payDate);

            pt.Execute();
            ValidatePaycheck(pt, empId, payDate, 8 * 15.23m, 9.42m + 19.42m);
        }
        public void TestCommissionedUnionMemberDues()
        {
            int empId = 1;
            var t     = new AddCommissionedEmployee(empId, "Bob", "Home", 1000.00m, 1m);

            t.Execute();
            int memberId = 7734;
            var cmt      = new ChangeMemberTransaction(empId, memberId, 9.42m);

            cmt.Execute();

            DateTime payDate = new DateTime(2020, 01, 24);
            var      pt      = new PaydayTransaction(payDate);

            pt.Execute();
            //2 Fridays
            var unionDues = 2m * 9.42m;

            ValidatePaycheck(pt, empId, payDate, 1000m, unionDues);

            payDate = new DateTime(2020, 01, 10);
            pt      = new PaydayTransaction(payDate);
            pt.Execute();

            ValidatePaycheck(pt, empId, payDate, 1000m, unionDues);
        }
        public void TestPaySingleCommissionedEmployeeTwoPeriods()
        {
            int empId = 3;
            AddCommissionedEmployee t = new AddCommissionedEmployee(empId, "Bob", "Home", 1000m, 0.5m);

            t.Execute();
            DateTime payDate            = new DateTime(2020, 02, 21);
            SalesReceiptTransaction srt = new SalesReceiptTransaction(payDate, 100m, empId);

            srt.Execute();
            SalesReceiptTransaction srt2 = new SalesReceiptTransaction(payDate.AddDays(-13), 100m, empId);

            srt2.Execute();

            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();

            ValidatePaycheck(pt, empId, payDate, 1000m + 0.5m * 200m);


            payDate = new DateTime(2020, 03, 06);
            pt      = new PaydayTransaction(payDate);
            pt.Execute();

            ValidatePaycheck(pt, empId, payDate, 1000m);
        }
        private void ValidatePaycheck(PaydayTransaction pt, int empId, DateTime payDate, decimal pay, decimal deductions = 0m)
        {
            Paycheck pc = pt.GetPaycheck(empId);

            Assert.That(pc, Is.Not.Null);
            Assert.That(pc.PayPeriodEndDate, Is.EqualTo(payDate));
            Assert.That(pc.GrossPay, Is.EqualTo(pay));
            Assert.That(pc.Deductions, Is.EqualTo(deductions));
            Assert.That(pc.NetPay, Is.EqualTo(pay - deductions));
        }
        public void TestPaySingleHourlyEmployeeNoTimeCards()
        {
            int empId           = 2;
            AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "Home", 15.25m);

            t.Execute();
            DateTime          payDate = new DateTime(2020, 2, 7);
            PaydayTransaction pt      = new PaydayTransaction(payDate);

            pt.Execute();
            ValidatePaycheck(pt, empId, payDate, 0.0m);
        }
        public void TestPaySingleSalariedEmployee()
        {
            int empId             = 1;
            AddSalariedEmployee t = new AddSalariedEmployee(empId, "Bob", "Home", 1000.00m);

            t.Execute();
            DateTime          payDate = new DateTime(2020, 11, 30);
            PaydayTransaction pt      = new PaydayTransaction(payDate);

            pt.Execute();

            ValidatePaycheck(pt, empId, payDate, 1000m);
        }
        public void TestPaySingleCommissionedEmployeeNoReceipts()
        {
            int empId = 3;
            AddCommissionedEmployee t = new AddCommissionedEmployee(empId, "Bob", "Home", 1000m, 5m);

            t.Execute();
            DateTime payDate = new DateTime(2020, 02, 21);

            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();

            ValidatePaycheck(pt, empId, payDate, 1000m);
        }
        public void TestPaySingleSalariedEmployeeOnWrongDate()
        {
            int empId             = 1;
            AddSalariedEmployee t = new AddSalariedEmployee(empId, "Bob", "Home", 1000.00m);

            t.Execute();
            DateTime          payDate = new DateTime(2020, 11, 29);
            PaydayTransaction pt      = new PaydayTransaction(payDate);

            pt.Execute();
            Paycheck pc = pt.GetPaycheck(empId);

            Assert.That(pc, Is.Null);
        }
        public void TestPaySingleCommissionedEmployeeWrongDate()
        {
            int empId = 3;
            AddCommissionedEmployee t = new AddCommissionedEmployee(empId, "Bob", "Home", 1000m, 5m);

            t.Execute();
            DateTime payDate = new DateTime(2020, 02, 20);

            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();
            var pc = pt.GetPaycheck(empId);

            Assert.That(pc, Is.Null);
        }
        public void TestPaySingleHourlyEmployeeOvertimeOneTimeCard()
        {
            int empId           = 2;
            AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "home", 15.25m);

            t.Execute();
            DateTime payDate = new DateTime(2020, 2, 7);

            TimeCardTransaction tct = new TimeCardTransaction(payDate, 9.0, empId);

            tct.Execute();

            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();
            ValidatePaycheck(pt, empId, payDate, (8m + 1.5m) * 15.25m);
        }
        public void TestPaySingleHourlyEmployeeTwoTimeCards()
        {
            int empId           = 2;
            AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "home", 15.25m);

            t.Execute();
            DateTime payDate = new DateTime(2020, 2, 7);

            TimeCardTransaction tct = new TimeCardTransaction(payDate, 2.0, empId);

            tct.Execute();
            TimeCardTransaction tct2 = new TimeCardTransaction(payDate.AddDays(-5), 5.0, empId);

            tct2.Execute();
            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();
            ValidatePaycheck(pt, empId, payDate, 7m * 15.25m);
        }
        public void TestPaySingleHourlyEmployeeOnWrongDate()
        {
            int empId           = 2;
            AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "home", 15.25m);

            t.Execute();
            DateTime payDate = new DateTime(2020, 2, 6);

            TimeCardTransaction tct = new TimeCardTransaction(payDate, 2.0, empId);

            tct.Execute();

            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();
            Paycheck pc = pt.GetPaycheck(empId);

            Assert.That(pc, Is.Null);
        }
        public void TestHourlyUnionMemberDues()
        {
            int empId = 1;
            var t     = new AddHourlyEmployee(empId, "Bob", "Home", 12.0m);

            t.Execute();
            int memberId = 7734;
            var cmt      = new ChangeMemberTransaction(empId, memberId, 9.42m);

            cmt.Execute();

            DateTime payDate = new DateTime(2020, 01, 24);
            var      pt      = new PaydayTransaction(payDate);

            pt.Execute();

            //1 Friday
            var unionDues = 9.42m;

            ValidatePaycheck(pt, empId, payDate, 0m, unionDues);
        }
        public void TestSalariedUnionMemberDuesFridaysTest()
        {
            int empId = 1;
            var t     = new AddSalariedEmployee(empId, "Bob", "Home", 1000.00m);

            t.Execute();
            int memberId = 7734;
            var cmt      = new ChangeMemberTransaction(empId, memberId, 9.42m);

            cmt.Execute();

            DateTime payDate = new DateTime(2020, 01, 31);
            var      pt      = new PaydayTransaction(payDate);

            pt.Execute();

            //5 Fridays in Jan
            var unionDues = 5m * 9.42m;

            ValidatePaycheck(pt, empId, payDate, 1000m, unionDues);
        }
        public void TestPaySingleHourlyEmployeeWithTimeCardSpanningTwoPayPeriods()
        {
            int empId           = 2;
            AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "home", 15.25m);

            t.Execute();
            DateTime payDate = new DateTime(2020, 2, 7);
            DateTime dateInPreviousPeriod = payDate.AddDays(-7);

            TimeCardTransaction tct = new TimeCardTransaction(payDate, 2.0, empId);

            tct.Execute();
            TimeCardTransaction tct2 = new TimeCardTransaction(dateInPreviousPeriod, 10.0, empId);

            tct2.Execute();

            PaydayTransaction pt = new PaydayTransaction(payDate);

            pt.Execute();
            ValidatePaycheck(pt, empId, payDate, 30.5m);
        }