public void When_GetViewModel_Then_should_call_correct_methods() { // Given const long riskAssessmentId = 100; const long companyId = 200; _employeeService .Setup(x => x.Search(It.Is<SearchEmployeesRequest>(y => y.CompanyId == companyId))) .Returns(new List<EmployeeDto>(){ new EmployeeDto()}); var riskAssessmentDto = new FireRiskAssessmentDto(); _riskAssessmentService .Setup(x => x.GetRiskAssessment(riskAssessmentId, companyId)) .Returns(riskAssessmentDto); // When target .WithRiskAssessmentId(riskAssessmentId) .WithCompanyId(companyId) .GetViewModel(); // Then _riskAssessmentService.VerifyAll(); _employeeService.VerifyAll(); }
public void When_GetViewModel_Then_should_return_correct_result() { // Given const long riskAssessmentId = 100; const long companyId = 200; var riskAssessmentDto = new FireRiskAssessmentDto() { Reference = "REF", Title = "My Title", PersonAppointed = "Legend" }; _riskAssessmentService .Setup(x => x.GetRiskAssessment(riskAssessmentId, companyId)) .Returns(riskAssessmentDto); _employeeService .Setup(x => x.Search(It.Is<SearchEmployeesRequest>(y => y.CompanyId == companyId))) .Returns(new List<EmployeeDto>() { new EmployeeDto() }); // When var result = target .WithRiskAssessmentId(riskAssessmentId) .WithCompanyId(companyId) .GetViewModel(); // Then Assert.That(result.CompanyId,Is.EqualTo(companyId)); Assert.That(result.RiskAssessmentId, Is.EqualTo(riskAssessmentId)); Assert.That(result.PersonAppointed, Is.EqualTo(riskAssessmentDto.PersonAppointed)); Assert.That(result.Reference, Is.EqualTo(riskAssessmentDto.Reference)); Assert.That(result.Title, Is.EqualTo(riskAssessmentDto.Title)); Assert.That(result.RiskAssessmentAssessors.Count(), Is.EqualTo(2)); }
private string GetSignificantFindingAdditionalInfo(FireRiskAssessmentDto fireRiskAssessment, long significantFindingId) { if (fireRiskAssessment.SignificantFindings != null && fireRiskAssessment.SignificantFindings.Any(x => x.Id == significantFindingId)) { return fireRiskAssessment.SignificantFindings.First(x => x.Id == significantFindingId).FireAnswer.AdditionalInfo; } else { return ""; } }
public void When_GetViewModel_Then_should_return_correct_result() { // Given const long riskAssessmentId = 100; const long companyId = 200; var riskAssessmentDto = new FireRiskAssessmentDto() { Reference = "REF", Title = "My Title", PersonAppointed = "Legend", SignificantFindings = new SignificantFindingDto[] { new SignificantFindingDto() { Id = 1, FireAnswer = new FireAnswerDto { Id=10001, Question = new QuestionDto { ListOrder = 1, Text="Test Title" } }, FurtherActionTasks = new LinkedList<TaskDto>() } } }; _riskAssessmentService .Setup(x => x.GetRiskAssessmentWithSignificantFindings(riskAssessmentId, companyId)) .Returns(riskAssessmentDto); // When var result = _target .WithRiskAssessmentId(riskAssessmentId) .WithCompanyId(companyId) .GetViewModel(); // Then Assert.That(result.CompanyId, Is.EqualTo(companyId)); Assert.That(result.RiskAssessmentId, Is.EqualTo(riskAssessmentId)); Assert.That(result.SignificantFindings.Count(), Is.EqualTo(riskAssessmentDto.SignificantFindings.Count())); Assert.That(result.SignificantFindings.First().Id, Is.EqualTo(riskAssessmentDto.SignificantFindings.First().Id)); }
public void When_GetViewModel_Then_should_call_correct_methods() { // Given const long riskAssessmentId = 100; const long companyId = 200; var riskAssessmentDto = new FireRiskAssessmentDto(); _riskAssessmentService .Setup(x => x.GetRiskAssessmentWithSignificantFindings(riskAssessmentId, companyId)) .Returns(riskAssessmentDto); // When _target .WithRiskAssessmentId(riskAssessmentId) .WithCompanyId(companyId) .GetViewModel(); // Then _riskAssessmentService.VerifyAll(); }
private static FireRiskAssessmentDto GetFireRiskAssessmentDto() { long section1Id = 1L; long question1Id = 10L; long question2Id = 20L; long question3Id = 30L; long answer1Id = 100L; long answer2Id = 200L; long answer3Id = 300L; var question1Dto = new QuestionDto { Id = question1Id, ListOrder = (int)question1Id, Text = "question " + question1Id, Information = "some info " + question1Id, QuestionType = QuestionType.YesNoNotApplicable, IsRequired = false }; var question2Dto = new QuestionDto { Id = question2Id, ListOrder = (int)question2Id, Text = "question " + question2Id, Information = "some info " + question2Id, QuestionType = QuestionType.YesNoNotApplicable, IsRequired = false }; var question3Dto = new QuestionDto { Id = question3Id, ListOrder = (int)question3Id, Text = "question " + question3Id, Information = "some info " + question3Id, QuestionType = QuestionType.YesNoNotApplicable, IsRequired = false }; var section1Dto = new SectionDto { Id = section1Id, ListOrder = (int)section1Id, ShortTitle = "short title " + section1Id.ToString(), Title = "normal title " + section1Id.ToString(), Questions = new List<QuestionDto> { question1Dto, question2Dto, question3Dto } }; long section2Id = 1L; long question4Id = 40L; long question5Id = 50L; long question6Id = 60L; long answer4Id = 400L; long answer5Id = 500L; long answer6Id = 600L; var question4Dto = new QuestionDto { Id = question4Id, ListOrder = (int)question4Id, Text = "question " + question4Id, Information = "some info " + question4Id, QuestionType = QuestionType.YesNoNotApplicable, IsRequired = false }; var question5Dto = new QuestionDto { Id = question5Id, ListOrder = (int)question5Id, Text = "question " + question5Id, Information = "some info " + question5Id, QuestionType = QuestionType.YesNoNotApplicable, IsRequired = false }; var question6Dto = new QuestionDto { Id = question6Id, ListOrder = (int)question6Id, Text = "question " + question6Id, Information = "some info " + question6Id, QuestionType = QuestionType.YesNoNotApplicable, IsRequired = false }; var section2Dto = new SectionDto { Id = section2Id, ListOrder = (int)section2Id, ShortTitle = "short title " + section2Id.ToString(), Title = "normal title " + section2Id.ToString(), Questions = new List<QuestionDto> { question4Dto, question5Dto, question6Dto } }; var checklistDto = new ChecklistDto { Sections = new List<SectionDto> { section1Dto, section2Dto } }; var fireAnswer1Dto = new FireAnswerDto { Id = answer1Id, Question = question1Dto, AdditionalInfo = "some information", YesNoNotApplicableResponse = YesNoNotApplicableEnum.No }; var fireAnswer2Dto = new FireAnswerDto { Id = answer2Id, Question = question2Dto, AdditionalInfo = "some information", YesNoNotApplicableResponse = YesNoNotApplicableEnum.Yes }; var fireAnswer3Dto = new FireAnswerDto { Id = answer3Id, Question = question3Dto, AdditionalInfo = "some information", YesNoNotApplicableResponse = YesNoNotApplicableEnum.NotApplicable }; var fireAnswer4Dto = new FireAnswerDto { Id = answer4Id, Question = question4Dto, AdditionalInfo = "some information", YesNoNotApplicableResponse = YesNoNotApplicableEnum.No }; var fireAnswer5Dto = new FireAnswerDto { Id = answer5Id, Question = question5Dto, AdditionalInfo = "some information", YesNoNotApplicableResponse = YesNoNotApplicableEnum.Yes }; var fireAnswer6Dto = new FireAnswerDto { Id = answer6Id, Question = question6Dto, YesNoNotApplicableResponse = YesNoNotApplicableEnum.NotApplicable }; var fireRiskAssessmentChecklistDto = new FireRiskAssessmentChecklistDto { Id = 12345L, Checklist = checklistDto, Answers = new List<FireAnswerDto> { fireAnswer1Dto, fireAnswer2Dto, fireAnswer3Dto, fireAnswer4Dto, fireAnswer5Dto, fireAnswer6Dto }, HasCompleteFailureAttempt = true }; var fireRiskAssessmentDto = new FireRiskAssessmentDto { LatestFireRiskAssessmentChecklist = fireRiskAssessmentChecklistDto }; return fireRiskAssessmentDto; }
public void When_get_Index_Then_should_return_the_correct_view_model() { //Given const long companyId = 100; const long riskAssessmentId = 50; var target = GetTarget(); IEnumerable<CompanyDefaultDto> companyDefaultsServiceReturnedPeopleAtRisk = new List<CompanyDefaultDto>() { new CompanyDefaultDto() { Id = 1, Name = "Test Name 1" }, new CompanyDefaultDto() { Id = 2, Name = "Test Name 2" } }; IEnumerable<CompanyDefaultDto> companyDefaultsServiceReturnedFireSafetyControlMeasures = new List<CompanyDefaultDto>() { new CompanyDefaultDto() { Id = 1, Name = "Test Name 1" }, new CompanyDefaultDto() { Id = 2, Name = "Test Name 2" } }; IEnumerable<CompanyDefaultDto> companyDefaultsServiceReturnedSourcesOfIgnition = new List<CompanyDefaultDto>() { new CompanyDefaultDto() { Id = 1, Name = "Test Name 1" }, new CompanyDefaultDto() { Id = 2, Name = "Test Name 2" } }; IEnumerable<CompanyDefaultDto> companyDefaultsServiceReturnedSourcesOfFuel = new List<CompanyDefaultDto>() { new CompanyDefaultDto() { Id = 1, Name = "Test Name 1" }, new CompanyDefaultDto() { Id = 2, Name = "Test Name 2" } }; _companyDefaultService.Setup(x => x.GetAllPeopleAtRiskForRiskAssessments(companyId,riskAssessmentId)).Returns(companyDefaultsServiceReturnedPeopleAtRisk); _companyDefaultService.Setup(x => x.GetAllFireSafetyControlMeasuresForRiskAssessments(companyId, riskAssessmentId)).Returns(companyDefaultsServiceReturnedFireSafetyControlMeasures); _companyDefaultService.Setup(x => x.GetAllSourceOfIgnitionForRiskAssessment(companyId,riskAssessmentId)).Returns(companyDefaultsServiceReturnedSourcesOfIgnition); _companyDefaultService.Setup(x => x.GetAllSourceOfFuelForRiskAssessment(companyId,riskAssessmentId)).Returns(companyDefaultsServiceReturnedSourcesOfFuel); var riskAssessmentFireSafetyControlMeasures = new List<FireRiskAssessmentControlMeasureDto>() { new FireRiskAssessmentControlMeasureDto { ControlMeasure = new FireSafetyControlMeasureDto() { Id = 2, Name = "Test Name 2" } } }; var riskAssessmentSourcesOfIgnition = new List<FireRiskAssessmentSourceOfIgnitionDto>() { new FireRiskAssessmentSourceOfIgnitionDto { SourceOfIgnition = new SourceOfIgnitionDto() {Id = 2, Name = "Test Name 2"} } }; var riskAssessmentPeopleAtRisk = new List<PeopleAtRiskDto>() { new PeopleAtRiskDto() { Id = 2, Name = "Test Name 2" } }; var riskAssessmentSourcesOfFuel = new List<FireRiskAssessmentSourceOfFuelDto>() { new FireRiskAssessmentSourceOfFuelDto { SourceOfFuel = new SourceOfFuelDto() {Id = 2, Name = "Test Name 2"} } }; var riskAssessmentDto = new FireRiskAssessmentDto() { PeopleAtRisk = riskAssessmentPeopleAtRisk, FireSafetyControlMeasures = riskAssessmentFireSafetyControlMeasures, FireRiskAssessmentSourcesOfIgnition = riskAssessmentSourcesOfIgnition, FireRiskAssessmentSourcesOfFuel = riskAssessmentSourcesOfFuel }; _fireRiskAssessmentService .Setup(x => x.GetRiskAssessmentWithFireSafetyControlMeasuresAndPeopleAtRisk(riskAssessmentId, companyId)) .Returns(riskAssessmentDto); //When var result = target.Index(companyId, riskAssessmentId) as ViewResult; //Then var model = result.Model as HazardsViewModel; Assert.That(model, Is.Not.Null); Assert.That(model.CompanyId, Is.EqualTo(companyId)); Assert.That(model.RiskAssessmentId, Is.EqualTo(riskAssessmentId)); Assert.That(model.PeopleAtRisk.Count(), Is.EqualTo(companyDefaultsServiceReturnedPeopleAtRisk.Count())); Assert.That(model.SelectedPeopleAtRisk.Count(), Is.EqualTo(riskAssessmentPeopleAtRisk.Count())); Assert.That(model.FireSafetyControlMeasures.Count(), Is.EqualTo(companyDefaultsServiceReturnedFireSafetyControlMeasures.Count())); Assert.That(model.SelectedFireSafetyControlMeasures.Count(), Is.EqualTo(riskAssessmentFireSafetyControlMeasures.Count())); Assert.That(model.SourceOfIgnitions.Count(), Is.EqualTo(companyDefaultsServiceReturnedSourcesOfIgnition.Count())); Assert.That(model.SelectedSourceOfIgnitions.Count(), Is.EqualTo(riskAssessmentSourcesOfIgnition.Count())); Assert.That(model.SourceOfFuels.Count(), Is.EqualTo(companyDefaultsServiceReturnedSourcesOfFuel.Count())); Assert.That(model.SelectedSourceOfFuels.Count(), Is.EqualTo(riskAssessmentSourcesOfFuel.Count())); }
public RiskAssessmentDto MapWithSiteAndRiskAssessor(RiskAssessment entity) { RiskAssessmentDto dto = null; if (entity.Self as MultiHazardRiskAssessment != null) { if(entity.Self as PersonalRiskAssessment != null) { dto = new PersonalRiskAssessmentDto(); var personalRiskAssessment = entity.Self as PersonalRiskAssessment; var personalRiskAssessmentDto = dto as PersonalRiskAssessmentDto; personalRiskAssessmentDto.Sensitive = personalRiskAssessment.Sensitive; personalRiskAssessmentDto.ChecklistGeneratorMessage = personalRiskAssessment.ChecklistGeneratorMessage; personalRiskAssessmentDto.PersonalRiskAssessementEmployeeChecklistStatus = personalRiskAssessment.PersonalRiskAssessementEmployeeChecklistStatus; personalRiskAssessmentDto.SendCompletedChecklistNotificationEmail = personalRiskAssessment.SendCompletedChecklistNotificationEmail; personalRiskAssessmentDto.CompletionDueDateForChecklists = personalRiskAssessment.CompletionDueDateForChecklists; personalRiskAssessmentDto.CompletionNotificationEmailAddress = personalRiskAssessment.CompletionNotificationEmailAddress; personalRiskAssessmentDto.Hazards = personalRiskAssessment.Hazards.ToList().Select(h => HazardDtoMapper.Map(h)).ToList(); } if(entity.Self as GeneralRiskAssessment != null) { dto = new GeneralRiskAssessmentDto(); } var multiHazardRiskAssessmentDto = dto as MultiHazardRiskAssessmentDto; var multiHazardRiskAssessment = entity.Self as MultiHazardRiskAssessment; if (multiHazardRiskAssessment != null) { multiHazardRiskAssessmentDto.Location = multiHazardRiskAssessment.Location; multiHazardRiskAssessmentDto.TaskProcessDescription = multiHazardRiskAssessment.TaskProcessDescription; multiHazardRiskAssessmentDto.CompletionDueDate = multiHazardRiskAssessment.CompletionDueDate; } } else if(entity.Self as FireRiskAssessment != null) { dto = new FireRiskAssessmentDto(); var fireRiskAssessment = entity.Self as FireRiskAssessment; var fireRiskAssessmentDto = dto as FireRiskAssessmentDto; fireRiskAssessmentDto.PersonAppointed = fireRiskAssessment.PersonAppointed; fireRiskAssessmentDto.PremisesProvidesSleepingAccommodation = fireRiskAssessment.PremisesProvidesSleepingAccommodation; fireRiskAssessmentDto.PremisesProvidesSleepingAccommodationConfirmed = fireRiskAssessment.PremisesProvidesSleepingAccommodationConfirmed; fireRiskAssessmentDto.Location = fireRiskAssessment.Location; fireRiskAssessmentDto.BuildingUse = fireRiskAssessment.BuildingUse; fireRiskAssessmentDto.NumberOfFloors = fireRiskAssessment.NumberOfFloors; fireRiskAssessmentDto.NumberOfPeople = fireRiskAssessment.NumberOfPeople; fireRiskAssessmentDto.ElectricityEmergencyShutOff = fireRiskAssessment.ElectricityEmergencyShutOff; fireRiskAssessmentDto.WaterEmergencyShutOff = fireRiskAssessment.WaterEmergencyShutOff; fireRiskAssessmentDto.GasEmergencyShutOff = fireRiskAssessment.GasEmergencyShutOff; fireRiskAssessmentDto.OtherEmergencyShutOff = fireRiskAssessment.OtherEmergencyShutOff; fireRiskAssessmentDto.CompletionDueDate = fireRiskAssessment.CompletionDueDate; } else { dto = new RiskAssessmentDto(); } dto.Id = entity.Id; dto.AssessmentDate = entity.AssessmentDate; dto.CreatedOn = entity.CreatedOn; dto.CompanyId = entity.CompanyId; dto.Reference = entity.Reference; dto.Status = entity.Status; dto.Title = entity.Title; dto.Deleted = entity.Deleted; dto.CreatedBy = entity.CreatedBy != null ? new AuditedUserDtoMapper().Map(entity.CreatedBy) : null; dto.RiskAssessmentSite = entity.RiskAssessmentSite != null ? new SiteStructureElementDtoMapper().Map(entity.RiskAssessmentSite) : null; dto.RiskAssessor = entity.RiskAssessor != null ? new RiskAssessorDtoMapper().MapWithEmployee(entity.RiskAssessor) : null; dto.NextReviewDate = entity.NextReviewDate; //Required for the API dto.Reviews = entity.Reviews != null ? entity.Reviews.Select(review => new RiskAssessmentReviewDto() { Comments = review.Comments ,CompletedBy = review.CompletedBy != null ? new EmployeeDtoMapper().Map(review.CompletedBy) : null ,CompletedDate = review.CompletedDate ,CompletionDueDate = review.CompletionDueDate, Id = review.Id, IsReviewOutstanding = review.IsReviewOutstanding ,ReviewAssignedTo = review.ReviewAssignedTo != null ? new EmployeeDtoMapper().Map(review.ReviewAssignedTo) : null }).ToList() : new List<RiskAssessmentReviewDto>(); return dto; }
public void Setup() { _fireRiskAssessmentService = new Mock<IFireRiskAssessmentService>(); _fireRiskAss = new FireRiskAssessmentDto() {RiskAssessor = new RiskAssessorDto()}; }
public void Setup() { _fireRiskAssessmentId = 1832L; _companyId = 526L; _fireRiskAssessment = new FireRiskAssessmentDto { Id = _fireRiskAssessmentId, CompanyId = _companyId, LatestFireRiskAssessmentChecklist = new FireRiskAssessmentChecklistDto { Id = _fireRiskAssessmentChecklistId, Checklist = new ChecklistDto { Sections = new List<SectionDto> { new SectionDto { Id = 1L, ShortTitle = "Test Section 1", Questions = new List<QuestionDto> { new QuestionDto { Id = 1L, ListOrder = 1, Text = "Test QuestionText 1", Information = "Test Information 1", }, new QuestionDto { Id = 2L, ListOrder = 2, Text = "Test QuestionText 2", Information = "Test Information 2", } } }, new SectionDto { Id = 2L, ShortTitle = "Test Section 2", Questions = new List<QuestionDto> { new QuestionDto { Id = 3L, ListOrder = 3, Text = "Test QuestionText 3", Information = "Test Information 3", }, new QuestionDto { Id = 4L, ListOrder = 4, Text = "Test QuestionText 4", Information = "Test Information 4", } } } } }, Answers = new List<FireAnswerDto> { new FireAnswerDto { Question = new QuestionDto { Id = 1L }, YesNoNotApplicableResponse = YesNoNotApplicableEnum.Yes, AdditionalInfo = "Test Additional Info 1" }, new FireAnswerDto { Question = new QuestionDto { Id = 2L }, YesNoNotApplicableResponse = YesNoNotApplicableEnum.No }, new FireAnswerDto { Question = new QuestionDto { Id = 3L } } } } }; _fireRiskAssessmentService = new Mock<IFireRiskAssessmentService>(); _fireRiskAssessmentChecklistService = new Mock<IFireRiskAssessmentChecklistService>(); _fireRiskAssessmentService .Setup(x => x.GetWithLatestFireRiskAssessmentChecklist(_fireRiskAssessmentId, _companyId)) .Returns(_fireRiskAssessment); _fireRiskAssessmentChecklistViewModelFactory = new FireRiskAssessmentChecklistViewModelFactory(_fireRiskAssessmentService.Object, null); }