public void GetSubordinatesForUser_Success() { // Setup TimesheetContext db = new TimesheetContext(); User user = db.Users.First(u => u.ManagerId.HasValue); // Test action TimesheetRepository repository = new TimesheetRepository(); var subordinates = repository.GetSubordinatesForUser(user.Id); // Assertions Assert.IsNotNull(subordinates); Assert.IsTrue(subordinates.Any()); }
/// <summary> /// Recursive function to get timesheet for self and all subordinates /// </summary> /// <param name="userId"></param> /// <returns></returns> private List <Time> GetTimes(int userId) { List <Time> times = new List <Time>(); // Get the current users timesheet times.AddRange(repository.GetTimesForUser(userId)); // Get all subordinates timesheets repository.GetSubordinatesForUser(userId) .ToList() .ForEach(u => times.AddRange(GetTimes(u.Id))); return(times); }