public void ApplySalaryIncreaseToSpecificDepartment_Should_IncreaseAllEmployeesOfThatDepartment() { #region Arrange var uowStub = Substitute.For <IUnitOfWork>(); var repositoryStub = Substitute.For <IGenericRepository <Employee> >(); var deptStub = Substitute.For <IGenericRepository <Department> >(); var mapperStub = Substitute.For <IMapper>(); var empLists = new List <Employee>(); for (int i = 0; i < 5; i++) { empLists.Add(new Employee() { Fname = "Random Employee", CurrentSalary = 18000M }); } deptStub.FindItem(Arg.Any <int>()).Returns(new Department() { Employees = empLists }); var service = new HumanResourceService(repositoryStub, deptStub, uowStub); #endregion List <Employee> empList = service.ApplySalaryIncreaseToSpecificDepartment(Arg.Any <int>(), 25); Assert.AreEqual(22500M, empList[4].CurrentSalary); }
public void AddEmployee_Should_AddPosition() { var dbContext = new PayrollContext(); var empRepo = new GenericRepository <Employee>(dbContext); var uow = new UnitOfWork(dbContext); var config = new MapperConfiguration(cfg => cfg.CreateMap <EmployeeViewModel, Employee>()); var mapper = new Mapper(config); var service = new HumanResourceService(empRepo, uow); var result = service.AddEmployee(new Employee() { Fname = "Sonny", Mname = "Ramirez", Lname = "Recio(Data)", Position = new Position() { BaseSalary = 15000M, IncreasePercentage = 15, Name = "Jr. Programmer" } }); Assert.AreEqual("Recio", result.Lname); //service.RemoveEmployee(result.Id); }
public void GetNetPayWithTaxDeductionOnly_Should_Deduct() { var uowStub = Substitute.For <IUnitOfWork>(); var repositoryStub = Substitute.For <IGenericRepository <Employee> >(); var deptStub = Substitute.For <IGenericRepository <Department> >(); var taxStub = Substitute.For <IGenericRepository <TaxTable> >(); taxStub .QueryItem(Arg.Any <Expression <Func <TaxTable, bool> > >()) .Returns(new TaxTable() { DeductionPercentage = 15, MaxSalary = 25000M, MinSalary = 18000M }); repositoryStub.FindItem(Arg.Any <int>()).Returns(new Employee() { CurrentSalary = 24000M }); var service = new HumanResourceService(repositoryStub, taxStub, uowStub); decimal result = service.GetNetPayWithTaxDeductionOnly(Arg.Any <int>()); Assert.AreEqual(20400M, result); }
public static void AddHumanResourceClient(this IServiceCollection services, IConfiguration configuration) { var url = configuration["RestClients:HrService"]; var client = new RestClient(url) { ThrowOnAnyError = true }; var hrService = new HumanResourceService(client); services.AddSingleton <IHumanResourceService>(hrService); }
public static IHumanResourceService InjectEmployeeServiceDependencies() { IHumanResourceService _empService; var dbContext = new PayrollContext(); var empRepository = new GenericRepository <Employee>(dbContext); var taxRepository = new GenericRepository <TaxTable>(dbContext); var deptRepository = new GenericRepository <Department>(dbContext); var uow = new UnitOfWork(dbContext); _empService = new HumanResourceService(empRepository, deptRepository, taxRepository, uow); return(_empService); }
public void AddEmployee_Should_AddToDb() { var dbContext = new PayrollContext(); var empRepo = new GenericRepository <Employee>(dbContext); var uow = new UnitOfWork(dbContext); var config = new MapperConfiguration(cfg => cfg.CreateMap <EmployeeViewModel, Employee>()); var mapper = new Mapper(config); var service = new HumanResourceService(empRepo, uow); var result = service.AddEmployee(new DDD.Domain.ViewModels.EmployeeViewModel() { Fname = "Sonny", Mname = "Ramirez", Lname = "Recio" }); Assert.AreEqual("Recio", result.Lname); service.RemoveEmployee(result.Id); }
public void ApplySalaryIncreasePerPositionPercentage_Should_IncreaseEmployeeSalary() { var uowStub = Substitute.For <IUnitOfWork>(); var repositoryStub = Substitute.For <IGenericRepository <Employee> >(); repositoryStub.FindItem(Arg.Any <int>()).Returns(new Employee() { CurrentSalary = 15000, Position = new Position() { Name = "Jr. Programmer", BaseSalary = 15000, IncreasePercentage = 25 } }); var service = new HumanResourceService(repositoryStub, uowStub); decimal result = service.ApplySalaryIncreasePerPositionPercentage(Arg.Any <int>()); Assert.AreEqual(18750M, result); }
public void InitializeEmployeeSalaryUsingPosition_Should_AddBaseSalaryToEmployee() { var uowStub = Substitute.For <IUnitOfWork>(); var repositoryStub = Substitute.For <IGenericRepository <Employee> >(); repositoryStub.FindItem(Arg.Any <int>()).Returns(new Employee() { Position = new Position() { Name = "Sr. Programmer", BaseSalary = 35000M } }); var service = new HumanResourceService(repositoryStub, uowStub); Employee emp = service.InitializeEmployeeSalaryUsingPosition(Arg.Any <int>()); decimal result = emp.CurrentSalary; Assert.AreEqual(35000M, result); }
public void AddEmployee_Should_Add() { var uowStub = Substitute.For <IUnitOfWork>(); var repositoryStub = Substitute.For <IGenericRepository <Employee> >(); var deptStub = Substitute.For <IGenericRepository <Department> >(); var mapperStub = Substitute.For <IMapper>(); var empLists = new List <Employee>(); var service = new HumanResourceService(repositoryStub, deptStub, uowStub); //mapperStub.Map<EmployeeViewModel, Employee>(Arg.Any<EmployeeViewModel>()).Returns(new Employee() { // Fname = "Sonny", // Lname = "Recio" //}); var result = service.AddEmployee(new EmployeeViewModel() { Fname = "Sonny", Lname = "Recio" }); Assert.AreEqual("Recio", result.Lname); }