public void CanGetAllDepartments() { DepartmentFactory departmentFactory = new DepartmentFactory(); var departmentList = departmentFactory.getAll(); Assert.NotNull(departmentList); Assert.IsType <List <Department> >(departmentList); foreach (var department in departmentList) { Assert.NotNull(department); Assert.True(department.GetType() == typeof(Department)); Assert.True(department.DepartmentId.GetType() == typeof(int)); Assert.NotNull(department.Label); Assert.NotNull(department.DepartmentId); } }
/** * Purpose: Reads user input for new employee information * Return: * void */ public static void ReadInput() { Employee newEmployee = new Employee(); DepartmentFactory departmentFactory = new DepartmentFactory(); EmployeeFactory employeeFactory = new EmployeeFactory(); while (newEmployee.FirstName == null || newEmployee.FirstName.Length <= 0) { Console.WriteLine("Enter employee first name and hit return: "); newEmployee.FirstName = Console.ReadLine(); } while (newEmployee.LastName == null || newEmployee.LastName.Length <= 0) { Console.WriteLine("Enter employee last name and hit return: "); newEmployee.LastName = Console.ReadLine(); } List <Department> allDepartments = departmentFactory.getAll(); while (newEmployee.DepartmentId <= 0 || allDepartments.TrueForAll(d => d.DepartmentId != newEmployee.DepartmentId)) { Console.WriteLine("\nAll Departments:"); foreach (Department d in allDepartments) { Console.WriteLine(d.DepartmentId + ". " + d.Label); } Console.WriteLine("Enter department ID: "); try { newEmployee.DepartmentId = Convert.ToInt32(Console.ReadLine()); if (allDepartments.TrueForAll(d => d.DepartmentId != newEmployee.DepartmentId)) { Console.WriteLine("Error! Please enter a number corresponding to the employee's department ID: "); } } catch { Console.WriteLine("Error! Please enter a number corresponding to the employee's department ID: "); } } Console.WriteLine($"Is {newEmployee.FirstName} {newEmployee.LastName} an administrator? Enter YES or NO: "); string administratorInput = Console.ReadLine(); while (administratorInput.ToUpper() != "YES" && administratorInput.ToUpper() != "NO") { Console.WriteLine($"I'm sorry, I'm not sure I know what you mean by {administratorInput}. Try again. "); administratorInput = Console.ReadLine(); } if (administratorInput.ToUpper() == "YES") { newEmployee.Administrator = true; } else { newEmployee.Administrator = false; } newEmployee.save(); Employee newlySavedEmployee = employeeFactory.getAll().Last(); Console.WriteLine(newlySavedEmployee.ToString()); EmployeeFactory.Instance.ActiveEmployee = newlySavedEmployee; Console.WriteLine($"{newlySavedEmployee.FirstName} {newlySavedEmployee.LastName} added. Press any key to return to main menu."); Console.ReadLine(); }