Esempio n. 1
0
        internal static List <Employee> Map(this List <EmployeeResponse> items)
        {
            List <Employee> response = new List <Employee>();

            foreach (var item in items)
            {
                Employee employee;
                if (Enum.TryParse(item.ContractTypeName, out ContractType type))
                {
                    employee = EmployeeFactory.Build(type);

                    employee.Id               = item.Id;
                    employee.Name             = item.Name;
                    employee.ContractTypeName = item.ContractTypeName;
                    employee.RoleId           = item.RoleId;
                    employee.RoleName         = item.RoleName;
                    employee.RoleDescription  = item.RoleDescription;
                    employee.HourlySalary     = item.HourlySalary;
                    employee.MonthlySalary    = item.MonthlySalary;

                    employee.Total = employee.CalculateSalary();

                    response.Add(employee);
                }
            }
            return(response);
        }
        public void Test_Employee_Factory_Correct_Run_For_Hourly_Salary()
        {
            //Params
            Employee employee;
            var      contractTypeName = "HourlySalaryEmployee";

            if (Enum.TryParse(contractTypeName, out ContractType type))
            {
                employee = EmployeeFactory.Build(type);

                employee.Id               = 2020;
                employee.Name             = "Andres";
                employee.ContractTypeName = "MonthlySalaryEmployee";
                employee.MonthlySalary    = 3500;
                employee.HourlySalary     = 1000;
                employee.AnnualSalary     = employee.CalculateSalary();

                Assert.AreEqual(employee.AnnualSalary, 1440000);
            }
        }