Beispiel #1
0
        public void CalculateTotalBenefitsCostTest()
        {
            var context      = new BenefitsContext();
            var paycheckCalc = new PaycheckCalc();

            context.Employees.Add(new Employee {
                EmployeeName = "Ali", BenefitCost = 900
            });
            context.SaveChanges();
            var employeeRec = context.Employees.Where(e => e.EmployeeName == "Ali").SingleOrDefault();

            context.Dependents.Add(new Dependent {
                DependentName = "Az", BenefitCost = 450, Employee = employeeRec
            });
            context.Dependents.Add(new Dependent {
                DependentName = "JJ", BenefitCost = 500, Employee = employeeRec
            });
            context.SaveChanges();

            paycheckCalc.CalculateTotalBenefitsCost("Ali");
            employeeRec = context.Employees.Where(e => e.EmployeeName == "Ali").SingleOrDefault();

            Assert.AreEqual(71, employeeRec.TotalBenefitCosts);
            Assert.AreEqual(1850, employeeRec.YearlyTotalBenefitsCost);
        }
Beispiel #2
0
 public void SaveEmployee(string employeeName, double employeeCost)
 {
     context.Employees.Add(new Employee {
         EmployeeName = employeeName.ToUpper(), BenefitCost = employeeCost
     });
     context.SaveChanges();
 }
Beispiel #3
0
        public void Seed_Database()
        {
            using (BenefitsContext db = new BenefitsContext())
            {
                var employeeFamily = new Employee()
                {
                    EmployeeName = "Bob",
                    BenefitCost  = 1000,
                    Dependents   = new List <Dependent>
                    {
                        new Dependent {
                            DependentName = "Judy", BenefitCost = 500
                        },
                        new Dependent {
                            DependentName = "Alfred", BenefitCost = 450
                        },
                        new Dependent {
                            DependentName = "Susan", BenefitCost = 500
                        }
                    }
                };

                // save data to db
                db.SaveChanges();
                db.Dispose();
            }
        }
        public void Handle(AddNewEmployee employee)
        {
            var addNewEmployee = _mapper.Map <AddNewEmployee, Employee>(employee);

            _db.Add(addNewEmployee);
            _db.SaveChanges();
        }
Beispiel #5
0
        public void CalculateYearlySalaryInfo()
        {
            var context      = new BenefitsContext();
            var paycheckCalc = new PaycheckCalc();

            context.Employees.Add(new Employee {
                EmployeeName = "Ali", YearlyTotalBenefitsCost = 1850
            });
            context.SaveChanges();

            paycheckCalc.CalculateYearlySalaryInfo("Ali");
            var employeeRec = context.Employees.Where(e => e.EmployeeName == "Ali").SingleOrDefault();

            Assert.AreEqual(52000, employeeRec.YearlySalary);
            Assert.AreEqual(52000 - 1850, employeeRec.YearlyNetPay);
        }
Beispiel #6
0
        public void CalculateSalaryInfoTest()
        {
            var context      = new BenefitsContext();
            var paycheckCalc = new PaycheckCalc();

            context.Employees.Add(new Employee {
                EmployeeName = "Ali", TotalBenefitCosts = 71
            });
            context.SaveChanges();

            paycheckCalc.CalculateSalaryInfo("Ali");
            var employeeRec = context.Employees.Where(e => e.EmployeeName == "Ali").SingleOrDefault();

            Assert.AreEqual(2000, employeeRec.Salary);
            Assert.AreEqual(2000 - 71, employeeRec.NetPay);
        }
Beispiel #7
0
        private void PrepareData()
        {
            using (var db = new BenefitsContext())
            {
                db.Database.CreateIfNotExists();
                db.Employees.Add(new Employee()
                {
                    FirstName = "FirstName",
                    LastName  = "LastName"
                });
                db.Employees.Add(new Employee()
                {
                    FirstName = "FirstName",
                    LastName  = "LastName"
                });

                db.SaveChanges();
            }
        }
Beispiel #8
0
        public void CalculateDependentBenefitsCostTest()
        {
            var context      = new BenefitsContext();
            var paycheckCalc = new PaycheckCalc();

            context.Employees.Add(new Employee {
                EmployeeName = "Ali", BenefitCost = 900
            });
            context.SaveChanges();

            var familyList = new List <string>();

            familyList.Add("Az");
            familyList.Add("JJ");
            paycheckCalc.CalculateDependentBenefitsCost("Ali", familyList);

            var dependentRecs   = context.Dependents.Where(e => e.Employee.EmployeeName == "Ali");
            var dependentsArray = dependentRecs.ToArray();

            Assert.AreEqual(450, dependentsArray[0].BenefitCost);
            Assert.AreEqual(500, dependentsArray[1].BenefitCost);
        }
Beispiel #9
0
 public bool Save()
 {
     return(_ctx.SaveChanges() >= 0);
 }
Beispiel #10
0
        private void SeedData(BenefitsContext ctx)
        {
            var People = new List <Person>()
            {
                new Person()
                {
                    PersonId    = 1,
                    FirstName   = "Fred",
                    LastName    = "Flintstone",
                    DateOfBirth = DateTime.Parse("1/2/1960"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 2,
                    FirstName   = "Wilma",
                    LastName    = "Flintstone",
                    DateOfBirth = DateTime.Parse("1/2/1965"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 3,
                    FirstName   = "Barney",
                    LastName    = "Rubble",
                    DateOfBirth = DateTime.Parse("1/2/1962"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 4,
                    FirstName   = "Conrad",
                    LastName    = "Hailstone",
                    DateOfBirth = DateTime.Parse("1/2/1995"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 5,
                    FirstName   = "Stony",
                    LastName    = "Curtis",
                    DateOfBirth = DateTime.Parse("3/2/1965"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 6,
                    FirstName   = "Rock",
                    LastName    = "Hudstone",
                    DateOfBirth = DateTime.Parse("4/2/1965"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 7,
                    FirstName   = "Daisy",
                    LastName    = "Kilgranite",
                    DateOfBirth = DateTime.Parse("5/2/1985"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                },
                new Person()
                {
                    PersonId    = 8,
                    FirstName   = "Jackie",
                    LastName    = "Kennerock",
                    DateOfBirth = DateTime.Parse("6/2/1975"),
                    IsEmployee  = true,
                    PayPeriods  = 26,
                    Salary      = 2000
                }
            };

            ctx.People.AddRange(People);

            var RecipTypes = new List <BenefitRecipientType>()
            {
                new BenefitRecipientType()
                {
                    BenefitRecipientTypeId = 1,
                    Cost        = 1000,
                    Description = "Employee annual benefit cost",
                    Label       = "Employee"
                },
                new BenefitRecipientType()
                {
                    BenefitRecipientTypeId = 2,
                    Cost        = 500,
                    Description = "Dependent annual benefit cost",
                    Label       = "Dependent"
                }
            };

            ctx.BenefitRecipientTypes.AddRange(RecipTypes);

            var Discs = new List <Discount>()
            {
                new Discount()
                {
                    DiscountId     = 1,
                    DiscountName   = "Name begins with 'A'",
                    Condition      = "startswith('A')",
                    Field          = "name",
                    Expression     = "{cost} - ({cost} * .1)",
                    DiscountAmount = 0.1m
                }
            };

            ctx.Discounts.AddRange(Discs);

            ctx.Meta.Add(new Meta());

            ctx.SaveChanges();
        }