public ProgramDetailDTO GetProgramDetailByID(int programID) { try { ProgramDetailDTO programDetailDTO = new ProgramDetailDTO(); //Call a DAL method to get program detail by id var program = _programRepository.Get(programID); programDetailDTO.ProgramId = program.Id; programDetailDTO.ProgramTitle = program.ProgramTitle; programDetailDTO.MaxHoursPerDay = _configurationRepository.GetMaximumHoursPerDay(); #region Get modules included to program List <ShortModuleDetailDTO> listModulesIncluded = new List <ShortModuleDetailDTO>(); //Call a DAL method to get list module List <Module> modules = _moduleRepository.GetModulesByArrayID(program.ArrayOfIncludedModules).ToList(); foreach (Module module in modules) { ShortModuleDetailDTO shortModule = new ShortModuleDetailDTO(); //Get id and TrainTime of module shortModule.ModuleId = module.Id; shortModule.TrainTime = _configurationRepository.GetMaximumHoursPerDay(); shortModule.ModuleTitle = module.Title; shortModule.Duration = module.Theory + module.Pratical; //Get TotalDate if ((shortModule.Duration % shortModule.TrainTime) != 0) { double temp = shortModule.Duration / shortModule.TrainTime; shortModule.TotalDate = Math.Truncate(temp) + 1; } else { shortModule.TotalDate = shortModule.Duration / shortModule.TrainTime; } //Get Competencies trained by this module List <CompetenceDTO> listCompetenciesTrained = new List <CompetenceDTO>(); List <Competence> CompetenciesTrained = _competenceRepository.GetCompetenciesByCompetenceID(module.ArrayOfTrainingCompetencies); foreach (var competence in CompetenciesTrained) { CompetenceDTO competenceDto = new CompetenceDTO(); competenceDto.CompetenceID = competence.Id; competenceDto.Name = competence.Name; competenceDto.Description = competence.Description; listCompetenciesTrained.Add(competenceDto); } shortModule.Competencies = listCompetenciesTrained; listModulesIncluded.Add(shortModule); } programDetailDTO.ModulesIncluded = listModulesIncluded; #endregion #region Get potential trainees List <ShortTraineeDetailDTO> listPotentialTrainees = new List <ShortTraineeDetailDTO>(); //Call a DAL method to get list potentail trainees List <Trainee> potentailTrainees = _traineeRepository.getTraineesByArrayId(program.ArrayOfNeedByPotentialTrainees); foreach (Trainee trainee in potentailTrainees) { ShortTraineeDetailDTO Shotttrainee = new ShortTraineeDetailDTO(); Shotttrainee.TraineeId = trainee.Id; var person = _personRepository.Get(trainee.PersonId); Shotttrainee.Name = person.Name; listPotentialTrainees.Add(Shotttrainee); } programDetailDTO.NeedByPotentialTrainees = listPotentialTrainees; #endregion #region Get total Duration double totalDuration = 0; foreach (ShortModuleDetailDTO module in programDetailDTO.ModulesIncluded) { totalDuration += module.Duration; } programDetailDTO.TotalDuration = totalDuration; #endregion return(programDetailDTO); } catch { return(null); } }
public void GetProgramDetailByIDReturnTrue() { //Arrange Person person1 = new Person() { Id = 1, Name = "Per1", Company = "Rosen" }; Trainee trainee1 = new Trainee() { Id = 1, PersonId = 1, Person = person1, DefaultDepartment = "Software Development", JobFunctions = "1", Competencies = "1", TargetedTrainings = "1", AttendedTrainings = "1" }; Person person2 = new Person() { Id = 2, Name = "Per2", Company = "Rosen" }; Trainee trainee2 = new Trainee() { Id = 2, PersonId = 2, Person = person2, DefaultDepartment = "Software Development", JobFunctions = "1", Competencies = "1", TargetedTrainings = "1", AttendedTrainings = "1" }; Person person3 = new Person() { Id = 3, Name = "Per3", Company = "Rosen" }; Trainee trainee3 = new Trainee() { Id = 3, PersonId = 3, Person = person3, DefaultDepartment = "Software Development", JobFunctions = "1", Competencies = "1", TargetedTrainings = "1", AttendedTrainings = "1" }; Program prg1 = new Program() { Id = 1, ProgramTitle = "test1", IncludedModules = "1", NeedByPotentialTrainees = "1,2,3" }; Module module1 = new Module() { Id = 1, CompetenciesTrained = "2", AreaOfObjective = "Game design", TypeId = 1, Title = "Game design basic", Objectives = "Learn 3Dmax and basic design skill", TopicsCovered = "Step 1, step 2, step 3", Exercises = "Capture the event object, pass $event as a parameter in the event callback from the template", Theory = 6.0, Pratical = 3.0, Methods = "instructor-led training, supported by multimedia presentation", ReferencesDoc = "urlXYZ", ExamInclude = false, RoomOrEquipment = "beamer, access to QAS, pc / laptop", LearningTransfer = "training system, daily work, discussion board", ExpirationDate = DateTime.Parse("01-01-2017"), TargetGroup = "Software Developer", }; Competence compe = new Competence() { Id = 2, Name = "3D Max Design Lvl1", Description = "Basic skills in coding and applying ...", }; //mock mockPersonRepository.Setup(repo => repo.Get(1)).Returns(person1); mockPersonRepository.Setup(repo => repo.Get(2)).Returns(person2); mockPersonRepository.Setup(repo => repo.Get(3)).Returns(person3); mockProgramRepository.Setup(repo => repo.Get(1)).Returns(prg1); mockConfigurationRepository.Setup(repo => repo.GetMaximumHoursPerDay()).Returns(8); mockModuleRepository.Setup(repo => repo.GetModulesByArrayID(new int[] { 1 })).Returns(new List <Module>() { module1 }); mockCompetenceRepository.Setup(repo => repo.GetCompetenciesByCompetenceID(new int[] { 2 })).Returns(new List <Competence>() { compe }); mockTraineeRepository.Setup(repo => repo.getTraineesByArrayId(new int[] { 1, 2, 3 })).Returns(new List <Trainee> { trainee1, trainee2, trainee3 }); //assert bool check = false; ProgramDetailDTO result = sutProgramAppService.GetProgramDetailByID(1); if (result.ProgramId == 1 && result.ProgramTitle == "test1" && result.TotalDuration == 9) { check = true; } Assert.AreEqual(true, check); }