public void Returns_Not_Planned_When_Employee_Has_Incomplete_Goals_Without_Learning_Days() { //arrange IEmployeeTopicProgressStatusStrategy strategy = new EmployeeTopicProgressStatusStrategy(); var topic = new Domain.Entity.LearningCalendar.Topic { Id = new Guid() }; var employee = new Employee { Id = Guid.NewGuid(), PersonalGoals = new List <PersonalGoal> { new PersonalGoal { Topic = topic, TopicId = topic.Id, CompletionDate = null }, new PersonalGoal { TopicId = topic.Id, CompletionDate = DateTime.Now } }, LearningDays = new List <LearningDay>() }; //act var status = strategy.GetStatus(employee, topic); //assert Assert.That(status == Status.NotPlanned); }
public Status GetStatus(Employee employee, Domain.Entity.LearningCalendar.Topic topic) { var relevantDays = employee .LearningDays .Where(day => day.GetDayTopicByTopicId(topic.Id) != null) .ToList(); var relevantGoals = employee.PersonalGoals .Where(goal => goal.TopicId == topic.Id) .ToList(); bool hasRelevantGoals = relevantGoals.Any(); bool hasIncompleteGoals = relevantGoals .Any(goal => goal.TopicId == topic.Id && !goal.IsComplete); if (!relevantDays.Any()) { if (!hasRelevantGoals || hasIncompleteGoals) { return(Status.NotPlanned); } return(Status.Learned); } bool isPlanned = IsPlanned(relevantDays, topic.Id); bool isComplete = IsComplete(relevantDays, hasIncompleteGoals, topic.Id); return((isPlanned, isComplete) switch { (true, _) => Status.Planned, (false, true) => Status.Learned, (false, false) => Status.NotPlanned });
public EmployeeCollectionStatus GetStatus(IEnumerable <Employee> employees, Domain.Entity.LearningCalendar.Topic topic) { var collectionStatus = new EmployeeCollectionStatus(); foreach (Employee employee in employees) { var employeeStatus = _employeeTopicProgressStatusStrategy.GetStatus(employee, topic); switch (employeeStatus) { case Status.NotPlanned: collectionStatus.OtherEmployees.Add(employee); break; case Status.Planned: collectionStatus.PlannedEmployees.Add(employee); break; case Status.Learned: collectionStatus.LearnedEmployees.Add(employee); break; default: throw new ArgumentOutOfRangeException(); } } AddTotalStatus(collectionStatus); return(collectionStatus); }
private GetTopicTreeOperationResponse.Topic MapTopic( Domain.Entity.LearningCalendar.Topic topic) { return(new GetTopicTreeOperationResponse.Topic { Children = topic.SubTopics?.Select(MapTopic).ToList() ?? new List <GetTopicTreeOperationResponse.Topic>(), Id = topic.Id, Subject = topic.Subject }); }
private UpdateTopicOperationResponse.Topic MapTopic(Domain.Entity.LearningCalendar.Topic topic) { return(new UpdateTopicOperationResponse.Topic { Id = topic.Id, ParentTopicId = topic.ParentTopic?.Id, ParentTopicSubject = topic.ParentTopic?.Subject, Subject = topic.Subject, Description = topic.Description }); }
public void Returns_Learned_When_Employee_Has_All_Goals_Complete_With_Complete_Learning_Days() { //arrange IEmployeeTopicProgressStatusStrategy strategy = new EmployeeTopicProgressStatusStrategy(); var topic = new Domain.Entity.LearningCalendar.Topic { Id = new Guid() }; var employee = new Employee { Id = Guid.NewGuid(), PersonalGoals = new List <PersonalGoal> { new PersonalGoal { Topic = topic, TopicId = topic.Id, CompletionDate = DateTime.Now }, new PersonalGoal { Topic = topic, TopicId = topic.Id, CompletionDate = DateTime.Now } }, LearningDays = new List <LearningDay> { new LearningDay { Date = DateTime.Today.AddDays(-1), LearningDayTopics = new List <LearningDayTopic> { new LearningDayTopic { TopicId = topic.Id, Topic = topic, ProgressStatus = ProgressStatus.Done } } } } }; //act var status = strategy.GetStatus(employee, topic); //assert Assert.That(status == Status.Learned); }
private GetSubordinateTopicTreeOperationResponse.Topic MapToResponse( Domain.Entity.LearningCalendar.Topic topic, List <Domain.Entity.LearningCalendar.Employee> employees) { var status = _employeeCollectionTopicProgressStatusStrategy.GetStatus(employees, topic); return(new GetSubordinateTopicTreeOperationResponse.Topic { Id = topic.Id, Subject = topic.Subject, Description = topic.Description, Children = topic.SubTopics.Select(subTopic => MapToResponse(subTopic, employees)).ToList(), PlannedEmployees = status.PlannedEmployees.Select(MapEmployee).ToList(), LearnedEmployees = status.LearnedEmployees.Select(MapEmployee).ToList(), NotPlannedEmployees = status.OtherEmployees.Select(MapEmployee).ToList(), TotalStatus = MapStatus(status) }); }
private GetEmployeeTopicTreeOperationResponse.Topic MapTopic( Domain.Entity.LearningCalendar.Topic root, Domain.Entity.LearningCalendar.Employee employee) { var children = root.SubTopics .Select(topic => MapTopic(topic, employee)) .ToList(); var status = _employeeTopicProgressStatusStrategy.GetStatus(employee, root); return(new GetEmployeeTopicTreeOperationResponse.Topic { Id = root.Id, ParentId = root.ParentTopicId, Subject = root.Subject, Description = root.Description, Children = children, Status = ProgressStatusMapper.MapStatus(status) }); }
public void Returns_Not_Planned_When_Employee_Has_No_Personal_Goals_And_Days() { //arrange IEmployeeTopicProgressStatusStrategy strategy = new EmployeeTopicProgressStatusStrategy(); var employee = new Employee { Id = Guid.NewGuid(), PersonalGoals = new List <PersonalGoal>(), LearningDays = new List <LearningDay>() }; var topic = new Domain.Entity.LearningCalendar.Topic { Id = new Guid() }; //act var status = strategy.GetStatus(employee, topic); //assert Assert.That(status == Status.NotPlanned); }
public async Task <CreateTopicOperationResponse> Execute(CreateTopicOperationRequest request) { var topic = new Domain.Entity.LearningCalendar.Topic { ParentTopicId = request.ParentTopic, Subject = request.Subject, Description = request.Description, }; try { await _topicRepository.CreateAsync(topic); } catch (DbUpdateException) { throw new TopicAlreadyExistsException(request.Subject); } return(new CreateTopicOperationResponse { Id = topic.Id }); }
private GetTopicDetailsOperationResponse.Employee MapEmployee(Domain.Entity.LearningCalendar.Employee employee, Domain.Entity.LearningCalendar.Topic topic) { var status = _employeeTopicProgressStatusStrategy.GetStatus(employee, topic); return(new GetTopicDetailsOperationResponse.Employee { Id = employee.Id, FullName = employee.FullName, ProgressStatus = ProgressStatusMapper.MapStatus(status) }); }
private GetTopicDetailsOperationResponse.Team MapTeam(Domain.Entity.LearningCalendar.Team team, Domain.Entity.LearningCalendar.Topic topic) { var employees = team.Employees .Concat(new[] { team.Manager }); var status = _employeeCollectionTopicProgressStatusStrategy.GetStatus(employees, topic); return(new GetTopicDetailsOperationResponse.Team { TeamId = team.Id, ManagerId = team.Manager.Id, ManagerFullName = team.Manager.FullName, EmployeeCount = status.PlannedEmployees.Count + status.LearnedEmployees.Count + status.OtherEmployees.Count, LearnedCount = status.LearnedEmployees.Count, PlannedCount = status.PlannedEmployees.Count, ProgressStatus = ProgressStatusMapper.MapStatus(status.TotalStatus) }); }