예제 #1
0
        public void should_calculate_benefits_cost_for_employee()
        {
            var employee = new Employee
            {
                FirstName  = "Sam",
                Dependents = new List <Dependent>
                {
                    new Dependent {
                        FirstName = "Bob"
                    },                                 // 500
                    new Dependent {
                        FirstName = "Carole"
                    },                                    // 500
                    new Dependent {
                        FirstName = "Ted"
                    },                                 // 500
                    new Dependent {
                        FirstName = "Alice"
                    }                                   // 450
                }
            };

            _calculator.CalculateBenefitsCostsFor(employee);

            // Ugh, mutation by reference. - HAS 06/25/2018
            employee.AnnualBenefitsCost.Should().Be(2950m);
            employee.BenefitsCostPerPaycheck.Should().Be(2950m / 26m);
        }
        public Task <CreateDependentResponse> Handle(CreateDependentRequest request, CancellationToken cancellationToken)
        {
            var dependent = Mapper.Map <Dependent>(request);

            var employee = _context.Employees.SingleOrDefault(e => e.Id == dependent.EmployeeId);

            if (employee == null)
            {
                return(Task.FromResult <CreateDependentResponse>(null));
            }

            if (employee.Dependents == null)
            {
                employee.Dependents = new List <Dependent>();
            }

            employee.Dependents.Add(dependent);

            var calculator = new BenefitsCalculator.BenefitsCalculator();

            calculator.CalculateBenefitsCostsFor(employee);

            _context.SaveChanges();

            return(CreateResponse(dependent, employee));
        }
        public Task <EmployeeResponse> Handle(CreateEmployeeRequest request, CancellationToken cancellationToken)
        {
            var employee = Mapper.Map <Employee>(request);

            var calculator = new BenefitsCalculator.BenefitsCalculator();

            calculator.CalculateBenefitsCostsFor(employee);

            _context.Employees.Add(employee);

            _context.SaveChanges();

            var response = Mapper.Map <EmployeeResponse>(employee);

            return(Task.FromResult(response));
        }