public void GetSuitableTrainersShouldReturnTrainers() { //Arrange Person person1 = new Person() { Id = 1, Name = "trainer1", Company = "Rosen" }; Person person2 = new Person() { Id = 2, Name = "trainer2", Company = "Rosen" }; Trainer trainer1 = new Trainer() { Id = 1, PersonId = 1, Person = person1, IsExternal = true, SuitableModules = "1,2" }; Trainer trainer2 = new Trainer() { Id = 2, PersonId = 2, Person = person2, IsExternal = false, SuitableModules = "1,3" }; Program prg = new Program() { Id = 1, ProgramTitle = "test", IncludedModules = "1", NeedByPotentialTrainees = "1,2,3" }; Module module = new Module() { Id = 1, CompetenciesTrained = "1,2,11,12", 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 = System.DateTime.Parse("02/01/2017"), TargetGroup = "Software Developer", PersonId = 1, }; //Mock mockProgramRepository.Setup(repo => repo.Get(1)).Returns(prg); List <Trainer> trnr = new List <Trainer>() { trainer1, trainer2 }; //mockTrainerRepository.Setup(repo => repo.GetAll()).Returns(trnr.AsQueryable()); mockPersonRepository.Setup(repo => repo.Get(1)).Returns(person1); mockPersonRepository.Setup(repo => repo.Get(2)).Returns(person2); mockProgramRepository.Setup(repo => repo.Get(1)).Returns(prg); mockTrainerRepository.Setup(repo => repo.GetAllIncluding(trainer => trainer.Person)).Returns(trnr.AsQueryable()); ShortTrainerDetailDTO t1 = new ShortTrainerDetailDTO() { TrainerId = 1, Name = "traner1" }; ShortTrainerDetailDTO t2 = new ShortTrainerDetailDTO() { TrainerId = 2, Name = "traner2" }; ListSuitableTrainerDTO expectedListSuitableTrainersObject = new ListSuitableTrainerDTO() { ListSuitableTrainers = new List <ShortTrainerDetailDTO>() { t1, t2 } }; //Act ListSuitableTrainerDTO ListSuitableTrainersObjectOutput = sutTrainerAppService.GetSuitableTrainers(1); bool flag = true; for (int i = 0; i < ListSuitableTrainersObjectOutput.ListSuitableTrainers.Count; i++) { if (ListSuitableTrainersObjectOutput.ListSuitableTrainers[i].TrainerId != expectedListSuitableTrainersObject.ListSuitableTrainers[i].TrainerId) { flag = false; break; } } //Assrest Assert.AreEqual(true, flag); }
public TrainingDetailDTO GetTrainingDetailByID(int trainingID) { try { TrainingDetailDTO returnTraining = new TrainingDetailDTO(); //Call a DAL method to get Training by TrainingId Training training = _trainingRepository.Get(trainingID); returnTraining.TrainingId = training.Id; returnTraining.ProgramId = training.ProgramId; var program = _programRepository.Get(training.ProgramId); returnTraining.ProgramName = program.ProgramTitle; returnTraining.StatusId = training.StatusId; returnTraining.StatusName = training.TrainingStatus.StatusName; //need to check returnTraining.StartDate = training.StartDate.ToString(); returnTraining.EndDate = training.EndDate.ToString(); returnTraining.TotalDuration = training.TotalDuration; returnTraining.MaxHoursPerDay = _configurationRepository.GetMaximumHoursPerDay(); #region Get array trainees assigned List <ShortTraineeDetailDTO> listTraineesAssigned = new List <ShortTraineeDetailDTO>(); //Call a DAL method to get trainees by array traineeIDs List <Trainee> listTrainees = _traineeRepository.getTraineesByArrayId(training.ArrayOfAssignedTrainees); foreach (var x in listTrainees) { ShortTraineeDetailDTO trainee = new ShortTraineeDetailDTO(); trainee.TraineeId = x.Id; var person = _personRepository.Get(x.PersonId); trainee.Name = person.Name; listTraineesAssigned.Add(trainee); } returnTraining.TraineesAssigned = listTraineesAssigned; #endregion #region Get array trainers assigned List <ShortTrainerDetailDTO> listTrainersAssigned = new List <ShortTrainerDetailDTO>(); //Call a DAL method to get trainers by array trainerIDs List <Trainer> trainerList = _trainerRepository.GetTrainersByArrayId(training.ArrayOfAssignedTrainers); foreach (var x in trainerList) { ShortTrainerDetailDTO trainer = new ShortTrainerDetailDTO(); trainer.TrainerId = x.Id; var person = _personRepository.Get(x.PersonId); trainer.Name = person.Name; listTrainersAssigned.Add(trainer); } returnTraining.TrainersAssigned = listTrainersAssigned; #endregion #region Get array modules included List <ShortModuleDetailDTO> listModulesIncluded = new List <ShortModuleDetailDTO>(); //Array moduleIDs ModuleArrangementDTO[] arrayModulesArrangement = JsonConvert.DeserializeObject <ModuleArrangementDTO[]>(training.ModuleArrangement); foreach (ModuleArrangementDTO moduleArrangement in arrayModulesArrangement.ToList()) { ShortModuleDetailDTO shortModule = new ShortModuleDetailDTO(); //Get id and TrainTime of module shortModule.ModuleId = moduleArrangement.ModuleId; shortModule.TrainTime = moduleArrangement.TrainTime; //With each ModuleId, we get module data from database by that ModuleId Module module = _moduleRepository.Get(moduleArrangement.ModuleId); 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> competencies = _competenceRepository.GetCompetenciesByCompetenceID(module.ArrayOfTrainingCompetencies); foreach (var competence in competencies) { 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); } returnTraining.ModulesArrangement = listModulesIncluded; #endregion return(returnTraining); } catch { return(null); } }