/// <summary> /// Count of participants by year /// </summary> /// <param name="programId"></param> /// <returns></returns> public async Task <SnapshotGraphDTO> GetProgramParticipantsByYear(int programId) { var childPrograms = programService.GetAllChildProgramsWithParent(programId); var dto = await SnapshotQueries.CreateGetProgramParticipantsByYearQuery(Context, childPrograms.Select(p => p.ProgramId).ToList()); return(dto); }
public void TestCreateGetProgramParticipantsByYearQuery() { var person = new Person { PersonId = 1 }; var person2 = new Person { PersonId = 2 }; var person3 = new Person { PersonId = 3 }; var active = new ProgramStatus { ProgramStatusId = ProgramStatus.Active.Id, Status = ProgramStatus.Active.Value }; var status = new ProjectStatus { ProjectStatusId = 1, Status = "status" }; DateTime endDate = DateTime.UtcNow; DateTime oldestDate = DateTime.UtcNow.AddYears(-5); DateTime project1StartDate = oldestDate.AddYears(2); DateTime project2StartDate = oldestDate.AddYears(3); var org = new Organization { OrganizationId = 1, OfficeSymbol = "ABCDE" }; var program = new Program { ProgramId = 1, Owner = org, OwnerId = org.OrganizationId, ProgramStatus = active, ProgramStatusId = active.ProgramStatusId }; var project = new Project { ProjectId = 1, ParentProgram = program, ProgramId = program.ProgramId, Status = status, ProjectStatusId = status.ProjectStatusId, StartDate = project1StartDate, EndDate = endDate }; var project2 = new Project { ProjectId = 2, ParentProgram = program, ProgramId = program.ProgramId, Status = status, ProjectStatusId = status.ProjectStatusId, StartDate = project2StartDate, EndDate = endDate }; var participant = new Participant { ParticipantId = 1, Person = person, PersonId = person.PersonId, Project = project, ProjectId = project.ProjectId }; var participant2 = new Participant { ParticipantId = 2, Person = person2, PersonId = person2.PersonId, Project = project, ProjectId = project.ProjectId }; var participant3 = new Participant { ParticipantId = 3, Person = person3, PersonId = person3.PersonId, Project = project2, ProjectId = project2.ProjectId }; project.Participants.Add(participant); project.Participants.Add(participant2); project2.Participants.Add(participant3); program.Projects.Add(project); program.Projects.Add(project2); context.Programs.Add(program); context.Projects.Add(project); context.Projects.Add(project2); context.Participants.Add(participant); context.Participants.Add(participant2); context.Participants.Add(participant3); List <int> programIds = new List <int>(); programIds.Add(program.ProgramId); var results = SnapshotQueries.CreateGetProgramParticipantsByYearQuery(context, programIds); Assert.IsTrue(results.Result.values.Where(x => x.Key == project1StartDate.Year).Select(v => v.Value).FirstOrDefault() == 2); Assert.IsTrue(results.Result.values.Where(x => x.Key == project2StartDate.Year).Select(v => v.Value).FirstOrDefault() == 1); }