示例#1
0
 private static void Dump()
 {
     foreach (var boss in Staff.Where(e => e.Boss == null))
     {
         Dump(0, boss);
     }
     Console.WriteLine();
     Console.WriteLine($"TOTAL: {Calculator.CalculateSalary(Staff):F2}");
 }
        public void TestNull()
        {
            var c = new SalaryCalculator(SalaryArgs);

            Assert.ThrowsException <ArgumentNullException>(() => c.CalculateSalary((Employee)null));
            Assert.ThrowsException <ArgumentNullException>(() => c.CalculateSalary((ManagerEmployee)null));
            Assert.ThrowsException <ArgumentNullException>(() => c.CalculateSalary((SalesEmployee)null));
            Assert.ThrowsException <ArgumentNullException>(() => c.CalculateSalary((List <Employee>)null));
        }
        public void TestManager()
        {
            var c              = new SalaryCalculator(SalaryArgs);
            var m              = new ManagerEmployee("John Doe", DateTime.Now, null);
            var e              = new Employee("Jane Doe", DateTime.Now, m);
            var eSalary        = c.CalculateSalary(e);
            var actualSalary   = c.CalculateSalary(m);
            var expectedSalary = SalaryArgs.BaseRate + SalaryArgs.ManagerLeadershipBonus * eSalary;

            Assert.AreEqual(expectedSalary, actualSalary);
        }
示例#4
0
        public static void Main(string[] args)
        {
            var salaryCalculator = new SalaryCalculator();//invoker

            salaryCalculator.AddSalaryCalculator(new JrSoftwareEngineerSalaryCalculator());
            salaryCalculator.CalculateSalary();


            salaryCalculator.AddSalaryCalculator(new ProjectManagerSalaryCalculator());
            salaryCalculator.CalculateSalary();
        }
        public void TestSales()
        {
            var c              = new SalaryCalculator(SalaryArgs);
            var s              = new SalesEmployee("John Doe", DateTime.Now, null);
            var m              = new ManagerEmployee("Jane Doe", DateTime.Now, s);
            var e              = new Employee("John Smith", DateTime.Now, m);
            var eSalary        = c.CalculateSalary(e);
            var mSsalary       = c.CalculateSalary(m);
            var actualSalary   = c.CalculateSalary(s);
            var expectedSalary = SalaryArgs.BaseRate + SalaryArgs.SalesLeadershipBonus * (eSalary + mSsalary);

            Assert.AreEqual(expectedSalary, actualSalary);
        }
        public void TestTotal()
        {
            var c            = new SalaryCalculator(SalaryArgs);
            var s            = new SalesEmployee("John Doe", DateTime.Now, null);
            var m            = new ManagerEmployee("Jane Doe", DateTime.Now, s);
            var e            = new Employee("John Smith", DateTime.Now, m);
            var eSalary      = c.CalculateSalary(e);
            var mSsalary     = c.CalculateSalary(m);
            var sSalary      = c.CalculateSalary(s);
            var actualSalary = c.CalculateSalary(new List <Employee> {
                s, m, e
            });
            var expectedSalary = eSalary + mSsalary + sSalary;

            Assert.AreEqual(expectedSalary, actualSalary);
        }
        public void Should_Be_Correct_Monthly_Gross_Salary()
        {
            SalaryCalculator salaryCalculator = new SalaryCalculator(_mockTaxCalculator.Object);
            var salary = salaryCalculator.CalculateSalary(60050, 9);

            salary.GrossSalary.ShouldEqual(5004);
        }
        public void Should_Be_Correct_Monthly_Gross_Salary()
        {
            _mockTaxCalculator.Setup(t => t.CalculateTax(It.IsAny <decimal>())).Returns(922);
            _mockSuperCalculator.Setup(t => t.CalculateSuper(It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(450);
            SalaryCalculator calculator = new SalaryCalculator(_mockTaxCalculator.Object, _mockSuperCalculator.Object);
            var salary = calculator.CalculateSalary(60050, 9);

            salary.GrossSalary.ShouldEqual(5004);
        }
        public void Should_Be_Correct_Net_Salary()
        {
            _mockTaxCalculator.Setup(t => t.CalculateTax(It.IsAny <decimal>())).Returns(922);
            _mockSuperCalculator.Setup(t => t.CalculateSuper(It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(450);
            SalaryCalculator calculator = new SalaryCalculator(_mockTaxCalculator.Object, _mockSuperCalculator.Object);
            var salary = calculator.CalculateSalary(60050, 9);

            salary.NetIncome.ShouldEqual(4082);
        }
        public void TestEmployee()
        {
            var c = new SalaryCalculator(SalaryArgs);

            // 0 years
            var e      = new Employee("John Doe", DateTime.Now, null);
            var salary = c.CalculateSalary(e);

            Assert.AreEqual(salary, SalaryArgs.BaseRate);

            // 5 years
            e      = new Employee("John Doe", DateTime.Now.AddYears(-5), null);
            salary = c.CalculateSalary(e);
            Assert.AreEqual(salary, SalaryArgs.BaseRate * (1M + 5M * SalaryArgs.EmployeeBonusPerYear));

            // 12 years
            e      = new Employee("John Doe", DateTime.Now.AddYears(-12), null);
            salary = c.CalculateSalary(e);
            Assert.AreEqual(salary, SalaryArgs.BaseRate * (1M + SalaryArgs.EmployeeBonusLimit));
        }
        public void Should_Be_Correct_Net_Salary()
        {
            //ITaxCalculator taxCalculator = new TaxCalculator();

            _mockTaxCalculator.Setup(t => t.CalculateTax(It.IsAny <decimal>())).Returns(922);

            SalaryCalculator calculator = new SalaryCalculator(_mockTaxCalculator.Object);

            var salary = calculator.CalculateSalary(60050, 9);


            _mockTaxCalculator.Verify((t => t.CalculateTax(It.IsAny <decimal>())), Times.Once);
            //_mockTaxCalculator.Verify((t => t.CalculateTax(It.IsAny<decimal>())), Times.Never);

            salary.NetIncome.ShouldEqual(4082);
        }
示例#12
0
        public void CalculateSalary(Employee employee, Company company, double salary)
        {
            "Given a company working Mo-Fr between 08:00-12:00 and 13:00-17:00"
            .x(() =>
            {
                company = new Company
                {
                    BusinessHours = new[]
                    {
                        new TimeSpan(12, 00, 00) - new TimeSpan(08, 00, 00),
                        new TimeSpan(17, 00, 00) - new TimeSpan(13, 00, 00)
                    }.ToList(),
                    WorkingDays = new[]
                    {
                        DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday
                    },
                };
            });

            "And an employee payed 30$ per hour"
            .x(() =>
            {
                employee = new Employee
                {
                    Contract = new EmploymentContract
                    {
                        Company       = company,
                        Employee      = employee,
                        SalaryPerUnit = 30,
                        SalaryUnit    = TimeSpan.FromHours(1)
                    }
                };
            });

            "When the employee has worked November 2021"
            .x(() =>
            {
                salary = SalaryCalculator.CalculateSalary(employee, DateTime.Parse("2021-11-01"), DateTime.Parse("2021-12-01"));
            });

            "Then his salary is "
            .x(() =>
            {
                salary.Should().Be(5280);
            });
        }
示例#13
0
        // Salary Calculator Event
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // Decimal for weeks worked as you can work a week and a half (1.5)
            decimal weeksWorked;
            // Use the enum put then convert to string for use in a switch case as seen in salary calculator method.
            string position = cbx_salaryCalculator.SelectedItem.ToString();

            // Try catch to avoid a crash on invalid data
            try
            {
                weeksWorked = decimal.Parse(tbx_weeksWorked.Text);
                decimal salary = SalaryCalculator.CalculateSalary(position, weeksWorked);
                lbl_salaryCalculator.Content = salary.ToString("C");
            }
            catch (SystemException ex)
            {
                MessageBox.Show($"Input data invalid. System Exception: {ex}");
            }
        }
示例#14
0
        public void CalculateSalary(Employee employee, Company company, double salary)
        {
            "Given a company working Mo-Fr between 08:00-12:00 and 13:00-17:00"
            .x(() => company = TestCompany.Working()
                               .On(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday)
                               .Daily.From(08, 00).To(12, 00)
                               .Daily.From(13, 00).To(17, 00).Company);

            "And an employee payed 30$ per hour"
            .x(() => employee = TestEmployee.Create()
                                .WithContract(TestEmployeeContract.For(company).Earning(30).Per(TimeSpan.FromHours(1))));

            "When the employee has worked November 2021"
            .x(() => salary = SalaryCalculator
                              .CalculateSalary(employee, DateTime.Parse("2021-11-01"), DateTime.Parse("2021-12-01")));

            "Then his salary is "
            .x(() => salary.Should().Be(5280));
        }
        public override void Execute()
        {
            //The BL is not allowed to run any queries, it can not even reference this assembly containing the
            //queries because that would be a cyclical reference. We need to give all data to the BL.
            IQueryable <SalaryCalculation> previousSalaries =
                QueryRunner.ExecuteQuery(new GetSalaryCalculationsForAnEmployee(db, _employeeId));

            var validation = new SalaryCalculationValidation();

            validation.ValidateSalaryCalculationPreConditions(_periodStartDate, _periodEndDate, previousSalaries);

            string idString = _employeeId;

            Taxcard taxCard = db.Taxcards.SingleOrDefault(card => card.EmployeeId == idString);

            var calculator = new SalaryCalculator();
            SalaryCalculationResults res = calculator.CalculateSalary(taxCard, _grossSalary);

            //Saving the new calculation is not BL, that's why it is here.
            var salaryCalc = new SalaryCalculation
            {
                //EmployeeId = _employeeId,
                //GrossAmount = _grossSalary,
                //NetAmount = res.NetSalary,
                //PeriodStartDate = _periodStartDate,
                //PeriodEndDate = _periodEndDate,
                //Tax = res.Tax,
                SalaryCalculationId = Guid.NewGuid().ToString()
            };

            db.SalaryCalculations.Add(salaryCalc);

            db.SaveChanges();

            //You could argue that sending this event could be BL. Or you can say it is an infrastructural concern, like using
            //a transaction (if that was required here). However, it can not really exist in the salary calculation core because
            //the core only calculates and the whole process is not done until the result is persisted. So I would say this is
            //the right place after all.
            MessageBus.Send(new SalaryCalculationDoneEvent());
        }
示例#16
0
        public CalculatorPage()
        {
            InitializeComponent();
            _shifts           = new ObservableCollection <Shift>();
            _salaryCalculator = new SalaryCalculator(_shifts);

            //Sets the content for the listview
            BindingContext = _shifts;

            MorningButton.Clicked += (sender, args) =>
            {
                _shifts.Add(new Shift(ShiftDatePicker.Date, true));
            };
            EveningButton.Clicked += (sender, args) =>
            {
                _shifts.Add(new Shift(ShiftDatePicker.Date, false));
            };
            CalcButton.Clicked += (sender, args) =>
            {
                if (_shifts.Count == 0)
                {
                    DisplayAlert("Villa", "Engar vaktir skráðar", "OK");
                }
                else
                {
                    this.Navigation.PushAsync(new PaycheckPage(_salaryCalculator.CalculateSalary()));
                }
            };
            //Disable highlight on item selected
            ShiftList.ItemTapped += (object sender, ItemTappedEventArgs e) => {
                if (e.Item == null)
                {
                    return;
                }
                ((ListView)sender).SelectedItem = null;
            };
        }