public async Task WhenRequestingEmployeesByUnitId_SubUnits_ThenItShouldBeReturned() { var unitId = 5; var subUnit1 = 10; var subUnit2 = 12; var dummyUnitId = 1337; // Arrange var emps = EmployeeFactory.GetFactory().Generate(5); emps[0].UnitId = unitId; emps[1].UnitId = subUnit1; emps[2].UnitId = subUnit2; emps[3].UnitId = subUnit2; emps[4].UnitId = dummyUnitId; await AddToPersonalDb(emps); // Act var url = $"{_customerId}/employees/?take=500&UnitIds={unitId}&UnitIds={subUnit1}&UnitIds={subUnit2}"; var employees = await _client.GetAsyncAndDeserialize <List <contract.Employee> >(url); // Asserts Assert.IsNotNull(employees); Assert.AreEqual(4, employees.Count); Assert.IsTrue(employees.Any(x => x.UnitId == unitId)); Assert.IsTrue(employees.Any(x => x.UnitId == subUnit1)); Assert.AreEqual(2, employees.Count(x => x.UnitId == subUnit2)); Assert.IsFalse(employees.Any(x => x.UnitId == dummyUnitId)); }
public async Task SetupForEachTest() { var employees = EmployeeFactory.GetFactory().Generate(NUMBER_OF_AUTOGENERATED_EMPLOYEES); await AddToPersonalDb(employees); var user = DbUserFactory.GetFactory(_customerId, _currentUserId).Generate(1); await AddToPersonalCommonDb(user); await AddPersonalAdminPermissionForUsers(); }
public async Task RequestingEmployees_FilterByLastNameCasing() { var employees = EmployeeFactory.GetFactory().Generate(10); await AddToPersonalDb(employees); var employeeUnderTest = employees.ElementAt(0); var url = $"{_customerId}/employees?lastName={employeeUnderTest.LastName.ToUpper()}"; var employeeList = await _client.GetAsyncAndDeserialize <List <contract.Employee> >(url); Assert.AreEqual(1, employeeList.Count); var e = employeeList.ElementAt(0); Assert.AreEqual(e.LastName, employeeUnderTest.LastName); }
private static void Main(string[] args) { var visitingEmployee = new VisitingEmployee() { EmployeeId = 593826, FirstName = "John", MiddleName = "", LastName = "Skull", DateOfBirth = new DateTime(1984, 3, 12), Gender = Gender.Male, RatePerVisit = 35, VisitCount = 13 }; var permanentEmployee = new PermanentEmployee() { EmployeeId = 513873, FirstName = "Ted", MiddleName = "", LastName = "M", DateOfBirth = new DateTime(1995, 6, 5), Gender = Gender.Male, JoinedDate = new DateTime(2016, 11, 10), MonthlySalary = 150 }; var contractEmployee = new ContractEmployee() { EmployeeId = 598764, FirstName = "Mary", MiddleName = "", LastName = "M", DateOfBirth = new DateTime(1993, 8, 15), Gender = Gender.Female, ContractStartDate = new DateTime(1995, 6, 5), ContractEndDate = new DateTime(1995, 6, 5), HourlyRate = 60, WorkingHoursPerDay = 8 }; var baseEmployeeFactory = EmployeeFactory.GetFactory(permanentEmployee); var employee = baseEmployeeFactory.CommonInitializations(); Console.WriteLine(employee); }
private static List <Employee> GenerateAndAddEmployees(List <int> potentialUnitIds, int numberOfEmployees, PersonalLegacyContext context) { List <int> userIds = null; using (var commonContext = _commonDbFactory.CreateDbContext().Result) { var currentMaxId = commonContext.Users.Max(u => u.UserId.Value); userIds = Enumerable.Range(currentMaxId + 1000, numberOfEmployees).ToList(); var dbId = commonContext.Customers.First(c => c.SticosCustomerId == _customerId).Id; foreach (var userId in userIds) { var users = DbUserFactory .GetFactory(dbId, potentialUnitIds, userId, 8675309 + userId) .Generate(); commonContext.Users.AddRange(users); } commonContext.SaveChanges(); } var employees = EmployeeFactory .GetFactory(potentialUnitIds) .Generate(numberOfEmployees); for (int i = 0; i < employees.Count; i++) { employees[i].UserId = userIds.ElementAt(i); } context.Employees.AddRange(employees); context.SaveChanges(); var employments = employees.Select(e => new Employment { EmployeeId = e.Id, Percentage = 100, StartDate = e.EmployeeStartDate }); context.Employments.AddRange(employments); context.SaveChanges(); return(employees); }
public async Task RequestingEmployees_PropertiesOnEmployee() { var employee = EmployeeFactory.GetFactory().Generate(1).FirstOrDefault(); var user = DbUserFactory.GetFactory(_customerId, employee.UserId.Value).Generate(1); await AddToPersonalDb(employee); await AddToPersonalCommonDb(user); var url = $"{_customerId}/employees"; var employeeList = await _client.GetAsyncAndDeserialize <List <contract.Employee> >(url); var e = employeeList.ElementAt(0); Assert.IsTrue(e.Id > 0); Assert.IsTrue(e.UserId > 0); Assert.IsFalse(string.IsNullOrWhiteSpace(e.FirstName)); Assert.IsFalse(string.IsNullOrWhiteSpace(e.LastName)); Assert.IsFalse(string.IsNullOrWhiteSpace(e.JobTitle)); Assert.IsFalse(string.IsNullOrWhiteSpace(e.Email)); Assert.IsFalse(string.IsNullOrWhiteSpace(e.Phone)); }